Sql-server – The database theDb is not accessible. (ObjectExplorer)

databasepermissionssql serversql-server-2008

I'm developing an ASP.NET MVC3 web app, which connects to a SQL Server 2008 R2 database.

Everything was working fine, until I started getting this error:

The database myDb is not accessible. (ObjectExplorer)

This issue appears also when I try and browse the database in SQL Server Management Studio. It seems I have somehow lost permission to access my database? I can browse other databases just fine.

I am using mixed mode authentication (up until now Windows Authentication has been working fine). If I login as sa I get the same error.

How can I give the required permissions back to my user account, if I cannot access the database?

What sort of things might have caused this to happen in the first place?

The only changes I have made recently have not been database related at all, I'm struggling to figure out what has caused this.

Update
Well, after restarting my computer, it all started working again :/
I didn't change anything, hadn't read the replies here yet. Very odd!

Best Answer

In the past I have found that this has been due to the DB owner being invild, like it was deleted from the SQL instance.

Try this from a query window:

use <database with issue>;
exec sp_changedbowner 'sa';

It should then allow you to browse the DB in the SSMS explorer.

If you are aren't using mixed mode authentication then sub out 'sa' with a domain account, preferably one that serves as the service account with SA rights.