I have an embedded database in an asp.net mvc project. If I try to write to the file, I sometimes get a write failed exception because the SQL Server can’t write to the file. How can I check an ObjectContext, if its writeable, without actually writing something to the database?
Share
You could execute something like this directly against the database to find out it if is read-only or not:
SELECT DATABASEPROPERTYEX(‘DatabaseName’,’Updateability’)
To do that you would use:
ObjectContext.ExecuteStoreCommand(..)(ObjectContext.Connection as EntityConnection).StoreConnection as SqlConnectionto get to the underlying database connection, and then create a SqlCommand.Once you’ve figured this out, I’d probably turn this into an Extension method so you could do something like this:
Hope this helps
Alex