How to Fix SQL Server Error 916 (Msg 916)

Published
Length
4 min read

Luis Felipe Dias

All posts

You see sql server error 916 when a login lacks rights to open a database. You fix it by mapping that server login to a valid user inside the database. This failure comes with severity level 14, which points to a permission gap. The server lets the person log in, but the target database blocks entry. Teams often hit this wall during routine maintenance or when adding new staff. What causes sql server error 916 in the database engine The official message says the server principal cannot open

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You see sql server error 916 when a login lacks rights to open a database. You fix it by mapping that server login to a valid user inside the database.

This failure comes with severity level 14, which points to a permission gap. The server lets the person log in, but the target database blocks entry. Teams often hit this wall during routine maintenance or when adding new staff.

What causes sql server error 916 in the database engine

The official message says the server principal cannot open the database under its current rights. In plain terms, a server login and a database user are two distinct items. A database user is the identity of a login when it opens a database. People who use many databases on one instance often have a login in master. If that login has no matching user in the target database, error 916 fires.

Sometimes the user exists, but an admin turned off its right to enter. All roles, including the public role, have the basic right to connect by default. If someone revokes that right or drops the user mapping, the session fails right away. Management tools also trigger this error when they scan every database on an instance. If a login can only read one database, scanning the others triggers this alert.

Orphaned users are another common cause after you move or restore a database. When you restore a backup to a new server, the old database users stay inside. Still, their linked server logins might be missing or have different security numbers on the new host. The engine sees a mismatch and blocks the login from entering the restored database.

How to diagnose and fix the failure safely in production

Start by checking which login failed and which database it tried to open. Log in with an admin account and look at the user list for that database. Check if the blocked login has a mapped database user in that specific database. If the user is missing, create a database user tied to the server login.

For access to one or a few databases, you can use a contained database user. This is a user with a password that is not tied to a login in master. To use this option, an admin must first enable contained databases on the server and database. Keep in mind that the engine supports thirteen types of database users for different needs.

Kubernetes API Server Access + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

When you grant rights, do not give out the owner role just to clear the error. Members of the owner role can do all maintenance tasks and can even drop the database. Instead, pick a fixed role that fits the actual job of the person or app. The permissions assigned to fixed database roles cannot be changed.

If the person only needs to run select queries, add them to the data reader role. Members of that role can read all data from all user tables and views. If they also need to change rows, add them to the data writer role. Members of that role can add, delete, or change data in all user tables. Also check that the user is not in a deny role by mistake. A deny data reader role stops a user from reading any table data or metadata.

How to prevent permission drift across database instances

Fixing one broken login is easy, but managing hundreds of logins across instances is hard. Giving every engineer a personal login on every server often leads to permission sprawl. People change teams, old accounts stay active, and manual role edits cause errors like 916.

A better pattern is to map team roles to central identity groups instead of single logins. You can also route database sessions through a central layer that checks identity before queries run. When a session runs, data masking can rewrite matched fields like emails or phone numbers in results. Card numbers and national IDs can also be replaced in query output to protect sensitive rows. This keeps database user counts low while still giving engineers the exact read or write rights they need.

Add runtime guardrails beside SQL Server

Role grants and network rules are needed setup for SQL Server. Still, an allowed user or agent tool can send a bad delete or read raw customer fields over a valid session. In practice, hoop.dev sits inline in the TDS protocol beside the database as a sidecar for your SQL Server. For every query an agent or human runs in production, hoop.dev decides whether to pass, mask, block, or escalate it for review.

With hoop.dev SQL Server controls, rules refuse banned statements before they run, hold risky queries for human review, and mask matched sensitive values in supported result columns in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for HIPAA, PCI DSS, SOX, and GDPR audits. See the source on GitHub.

Frequently asked questions

Does sql server error 916 mean my password is wrong?

No, your password worked fine at the server level. The error means your login lacks a mapped user or permission inside the specific database you picked.

Why do I get error 916 when clicking the database list in my client tool?

Many visual tools try to read properties from every database on the server to build a tree view. If your login only has rights to one database, the tool hits error 916 on the rest.

Should I fix error 916 by adding the login to the server admin role?

No, never grant server admin or database owner rights just to fix a login error. Map the login to a database user and assign a narrow role like data reader instead.

The query runs. The emails stay hidden.