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

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

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.

  1. Open SSMS and Click Connect Database Engine.
  2. Enter the SQL Server instance name and provide the SQL server authentication username and password.
  3. Click the ‘Options <<‘ button and choose the ‘Connection Properties’ tab.
  4. Enter the database name in the ‘Connect to database’ text box. By default, this is the master database.
  5. 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 a decade 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.
I am always interested in new challenges so if you need consulting help, reach me at kunalrathi55@gmail.com.

Shopping Cart
Scroll to Top