[DBMS-MSSQL:11006#916] The server principal “NT AUTHORITY\SYSTEM” is not able to access the database under the current security context

If you encounter the error message:

[DBMS-MSSQL:11006#916] The server principal "NT AUTHORITY\SYSTEM" 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 the gear button. At the opened “Connect to Server” window you need to select “Microsoft SQ: Server (local) as your Server type, choose “Windows Authentication” and enter User Name and Password. Press “Test Connection” to make sure that you have specified the correct data and then click on “Save & Close” to save and apply new settings.

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 a user member of db_owner group:

use <dbname>
exec sp_addrolemember 'db_owner', '<username>';