Link to home
Create AccountLog in
Avatar of rodqxo
rodqxo

asked on

Avoiding "The server principal ... is not able to access the database ... under the current security context" runtime on 'USE [db]', how?

In my code, I gather all database names and tables from a database server. However, there are cases where my User ID does not have the permission to "USE [database]". It would be too late because I will get an exception and some do not favor code that use exception handlers.

Here is the runtime error again:
"The server principal ... is not able to access the database ... under the current security context" ...

Is there an SQL query that I could use before issuing "USE [database]" that determines whether or not I could really "USE [database]" without getting the runtime error above?
ASKER CERTIFIED SOLUTION
Avatar of Surendra Nath
Surendra Nath
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account