I have a user that is attempting to access DatabaseA which he has rights too but he keeps getting the below error (he has access to DatabaseA but doesn’t have rights to DatabaseB):
The server principal "Domain\Username" is not able to access the database "DatabaseB" under the current security context.
Because he doesn’t have access to DatabaseB, this makes sense at first. Unfortunately, he’s not calling DatabaseB in any way.
-
I’ve watched this come through the server using Profiler down to the statement levels using no
filters. I can see his connections and the error come through but
there is no indication that DatabaseB is being hit in any way. -
I’ve reviewed the stored proc that he is attempting to run. It contains a simple select statement that accesses only tables within DatabaseA.
-
I was able to work around this by giving him access to DatabaseB but
this is not a viable long term solution. -
I’ve confirmed that the user is not orphaned
-
I’ve searched Google and there are tons of posts regarding this error
but none that describe this scenerio.
If anyone has seen this or has an idea about it, I’d truly appreciate it!
If the connection doesn’t specify a database, then the user is connecting to a default database. Check the login information in SQL Server for the default database. The default is probably set to DatabaseB, but the login isn’t a user in the database.
You can use Object Browser to view the information. Connect to your SQL Server, navigate the tree to Security > Logins and select the login. Right-click and select properties. Default database is located near the bottom of the form on the General tab.