// SQL Server error reference

SQL Server error 916: Login can't access the database

The login connected to the server but has no user in this database and no guest access, so it can't use the database in the current security context.

Error number
916
Severity
14
Category
Permissions
Error message
The server principal "%.*ls" is not able to access the database "%.*ls" under the current security context.

What it means

A login gets into a database through a database user mapped to it, through a Windows group, or through the guest user if guest is enabled. Error 916 means none of those apply for this database. It often appears in SSMS when Object Explorer tries to read properties of every database, including ones you aren't a user in.

Common causes

  • The login has no database user in that database.
  • The database was restored from another server and its user is orphaned (its SID doesn't match the login).
  • Code switches to the database with USE, or a cross-database query or view touches a database the login can't access.
  • Running under EXECUTE AS USER, which is scoped to the current database, then touching another database.

How to fix it

  1. Create a user for the login in the database and grant it a role.

    USE SalesDb;
    CREATE USER app_user FOR LOGIN app_user;
    ALTER ROLE db_datareader ADD MEMBER app_user;
  2. If the database came from another server, remap the orphaned user to the login.

    USE SalesDb;
    ALTER USER app_user WITH LOGIN = app_user;
  3. List orphaned users in the current database.

    SELECT dp.name
    FROM sys.database_principals dp
    LEFT JOIN sys.server_principals sp ON sp.sid = dp.sid
    WHERE dp.type IN ('S', 'U') AND sp.sid IS NULL AND dp.authentication_type_desc = 'INSTANCE';

Related errors

More permissions errors

The code and message text are from the Microsoft Database Engine events and errors reference. Browse the full SQL Server error list or search every database error.

// fewer errors, faster fixes

Work on SQL Server in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQL Server and the other databases you use.