Principal "username" is not able to access the database "db" under the current security context.

Just to remind me because I always forget about it

I was trying to do some maintenance on the SQL database that I use for one of my sites.

I used SQL Management Studio to connect ok but when I tried to expand the database container I got this error (with username and dbname being specific to your site)

The server principal "username" is not able to access the database "dbname" under the current security context.
.Net SqlClient Data Provider in SQL Server Management Studio.

 

It’s a shared hosting plan so obviously the security is pretty tight but I couldn’t even view my own database

Fortunately the answer is simple (I found the answer on lots of sites but this the first one i found –thanks!)

Reason:
This is because the MS SQL Server is attempting to execute a T-SQL query to retrieve a list of databases along with additional information about those databases. One of those pieces of information is "Collation", which you will not have permission to action for all databases as you’re in a shared hosting environment and you only have access to your database alone.

Solution:
Step 1: In Object Explorer, click Databases
Step 2: Display Object Explorer Details (F7) or View > Object Explorer Details
Step 3: Right click the column headers and de-select "Collation"
Step 4: Refresh Databases

 

Easy enough – once I’d stopped the collation field from displaying all was well

The following two tabs change content below.
Andy Parkes is Technical Director at Coventry based IT support company IBIT Solutions. Formerly, coordinator of AMITPRO and Microsoft Partner Area Lead for 2012-2013. He also isn't a fan of describing himself in the third person.

Latest posts by Andy Parkes (see all)

1 thought on “Principal "username" is not able to access the database "db" under the current security context.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.