The server principal “NT AUTHORITY\SYSTEM” is not able to access the database “database-name” under the current security context

If you encounter the error message: “The server principal “NT AUTHORITYSYSTEM” is not able to access the database database-name under the current security context”, you will find the solution below:

Go to the “SQL Server” sections and click on gear button. At the opened “Connect to SQL Server on this computer” window you need select “Windows Authentication” and enter User Name and Password. Press “Test SQL Server Connection” to make sure that you have specified the correct data and then click on “Save & Close” to save and apply new settings.

Connect to SQL Server (SQLBackupAndFTP)

 

Another reason you get this error message is that database-name doesn’t map to the user from behalf whom you try to connect SQL Server. To map a user to a particular database and grants him permissions please follow these steps:

SQL Server Management Studio

1.  Run SQL Server Management Studio and click “Security” > “Logins” > and right-click on the user you need then select “Properties”.
2. Then click “User Mapping“, select a database and specify a role for the selected user.

Or you can do it via

T-SQL Commands

Change default database of a login:

alter login <loginname> with default_database = <dbname>;

Create a user in a database for a given login:

use <dbname>;
create user <username> from login <loginname>;

Make an user member of db_owner group:

use <dbname>
exec sp_addrolemember ‘db_owner’, ‘<username>’;

[Total: 5    Average: 4.4/5]