Wednesday, December 15, 2010

The server principal is not able to access the database under the current security context.

 

I reproduced the error below;

Issue 1:

Msg 916, Level 14, State 1, Line 1
The server principal "Test_Login" is not able to access the database "testdb" under the current security context.

1. Created database ‘testdb’

2. Created the login ‘Test_Login’. The login not granted access on the database ‘testdb’

3. On logging on ‘Test_Login’, tried accesing the database ‘testdb’ and got the error.

clip_image002

From the error message, when the server principal ( login) does not have access on the database the error occurs.

Resolution 1:
Grant the database access for the login. For example;

Use testdb
go

Create User Test_Login for Login Test_Login
go

Issue 2:

The database is in “Restricted Mode”

image

Try the query below, to access the database in different user context

Use testdb
go
execute as user='test_login'
go

Msg 916, Level 14, State 1, Line 1
The server principal "Test_Login" is not able to access the database "testdb" under the current security context.


Reference : 
"The server principal LoginName is not able to access the database DatabaseName under the current security context"

No comments: