“The server principal “login_name” is not able to access the database “database_name” under the current security context.”
You receive this error when you do not have sufficient privileges in the database that you are trying to access.
Make sure that the Login you connect to SQL Server Instance has sufficient privileges to access the relavant database.
You can follow these steps:
– Run SQL Server Management Studio.
– Connect to the related SQL Server Instance with a user account that can modify Login.
– Expand the Logins under the Security to find the corresponding Login and right click on this login and then click Properties.
– Click User Mapping and select the database you want to give the access right to the login from “Users mapped to this login” list.
In the screenshot below, we will map the login named test to the database AdventureWorks.
or you can use T-SQL code as follows:
CREATE USER [user_name] FOR LOGIN [login_name]