1

Command - 1 (Running on 'Master')

*CREATE LOGIN [login_Name] WITH PASSWORD=N'XXXXXX'*

Command - 2 (Running on 'Database_name')

*ALTER USER [User_name] WITH LOGIN= [login_name]

EXEC sp_addrolemember N'db_owner', N'Database_Name'*

When I try logging to 'Database_Name' or try to make a connection to this database with the newly created Login_name and Password, I am getting the following error sometimes:

The server principal "XXX" is not able to access the database "XXX" under the current security context. Cannot open database "XXX" requested by the login. The login failed. Login failed for user 'XXX'.

I made sure that the altered user is not orphan user by matching it's SID with the Login's SID.

ISSUE: After resetting the password and user, the above error shows up sporadically. Sometimes I can make a connection in just a second after running the above commands. The other times it may take up to 15 minutes before I can connect to the database.

  • Try this https://blogs.technet.microsoft.com/mdegre/2010/08/28/the-server-principal-sqlloginname-is-not-able-to-access-the-database-mydatabasename-under-the-current-security-context/ – Jayendran Aug 10 '18 at 02:35
  • As I mentioned, I am already checking for Orphaned Users and correcting it if necessary. The issue still persists. – Amber Gupta Aug 10 '18 at 18:17
  • I had this problem and I had to manual search and delete all my old user from master and other databases to create it from scratch. @Jayendran I couldn't use all instructions indicated at your link, it might be because that info is from 2010 and the SQL server has evolved since then. – dchang Dec 03 '20 at 15:49

0 Answers0