Cannot connect to <servername>.database.windows.net.
The server principal “username” is not able to access the database “master” under the current security context.
Cannot open user default database. Login failed.
Login failed for user ‘testlogin’. (Microsoft SQL Server, Error: 916)
Cause
This error is caused because the user username cannot access the master database on Azure SQL server <servername>.database.windows.net.
Solution
If this error appears when connecting to Azure SQL server or SQL Server from SQL Server Management Studio (SSMS), follow the below steps to fix it.
- Open SSMS and Click Connect Database Engine.
- Enter the SQL Server instance name and provide the SQL server authentication username and password.
- Click the ‘Options <<‘ button and choose the ‘Connection Properties’ tab.
- Enter the database name in the ‘Connect to database’ text box. By default, this is the master database.
- Click Connect.
Another solution is to grant access to the user username on the master database. Execute the below script on the master database. However, if user do not need to have access to master database, then this should not be done.
CREATE USER username FROM LOGIN loginname WITH DEFAULT_SCHEMA=dbo
Pro tips:
1 Follow this article to learn how to grant access to the Azure SQL database.
We have seen how to resolve The server principal is not able to access the database “master” under the current security context. error in Azure SQL or SQL Server connection.
See more
Kunal Rathi
With over 13 years of experience in data engineering and analytics, I've assisted countless clients in gaining valuable insights from their data. As a dedicated supporter of Data, Cloud and DevOps, I'm excited to connect with individuals who share my passion for this field. If my work resonates with you, we can talk and collaborate.