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
Latest posts by Andy Parkes (see all)
- Copenhagen Marathon 2022 - May 23, 2022
- Amager Strandpark parkrun - May 17, 2022
- Beacon Parkrun - May 7, 2022
1 thought on “Principal "username" is not able to access the database "db" under the current security context.”