How to Fix SQL Server Error 10531 (Msg 10531)
You get sql server error 10531 when a user lacks rights to read the plan cache. You fix it by granting the view server state permission to the account. This failure returns message 10531 at severity level 16 in the database engine. It stops teams from making a new plan guide from cached execution plans. Database admins often see this during query tuning tasks in production. What causes sql server error 10531 in the engine The database engine throws this error when a user tries to create a pl
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 get sql server error 10531 when a user lacks rights to read the plan cache. You fix it by granting the view server state permission to the account.
This failure returns message 10531 at severity level 16 in the database engine. It stops teams from making a new plan guide from cached execution plans. Database admins often see this during query tuning tasks in production.
What causes sql server error 10531 in the engine
The database engine throws this error when a user tries to create a plan guide from the cache. The official message says the user does not have adequate permissions for this task. The engine checks for the view server state right before reading the plan cache. If the login lacks this server right, the engine blocks the action right away.
In this system, a database user is the identity of a login inside a database. People who need to use many databases often use a login in the master database. Some teams use a contained database user with a password for one database instead. That contained user is not tied to a login in the master database. An admin must turn on contained databases on the server and database first. Across the platform, there are 13 types of database users available.
Because plan cache data lives at the server level, database roles are not enough. Fixed database roles like the data reader role only let users read user tables and views. Even the database owner role is scoped to config and maintenance inside one database. A database owner can drop the database, but still miss server state rights. Also, you cannot change the permissions assigned to fixed database roles.
How to diagnose and fix the permission failure
First, find out which login ran the command that triggered message 10531. Check whether that account uses a master login or a contained database user. A contained user does not have a master login to hold server permissions. If the person uses a contained user, they cannot inspect the server plan cache.
Next, check the server permissions for the login in the master database. Give the login the view server state permission as the error message asks. Do not add the login to broad admin roles just to fix a plan guide. Broad roles give too much power and create risk for your production data.
Kubernetes API Server Access + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Keep database rights tight while you grant the needed server permission. Use standard role commands to place the user in the right database role. If someone only reads data, the data reader role is a safe choice. If you must block reads or writes, use the deny data reader or writer roles. Remember that all database roles, including the public role, have basic connect rights.
How to manage query tuning access safely
Tuning queries in production often forces engineers to touch sensitive database systems. Granting permanent server permissions to every developer increases the risk of human error. A better path is to limit who can run tuning commands directly.
Teams should review why a user needs to pull plans from the cache. Often, one senior admin can create the plan guide during a planned window. Other engineers can test their queries in a staging setup first. When engineers run reads in production, data masking can rewrite emails and phone numbers in results. It can also rewrite card numbers and national IDs to keep customer records safe.
Check SQL Server batches and results on the wire
SQL Server logins and roles decide who connects. They do not check what each TDS batch does or mask sensitive values in returned rows. With hoop.dev, you run an open-source proxy, a sidecar for your SQL Server, inline in the TDS wire protocol. On every batch an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
Before a batch hits the server, hoop.dev guardrails refuse disallowed actions with a native TDS error or hold risky statements for approval. On the way back, hoop.dev data masking rewrites sensitive values in supported result columns in memory, and every decision is logged. Explore the MIT-licensed project on GitHub.
Frequently asked questions
What is the severity level of message 10531?
Message 10531 has a severity level of 16 in the database engine. This level means the error came from a user mistake or missing permission. It does not mean the database server has a hardware or software crash.
Can I change a fixed database role to fix this error?
No, you cannot change the permissions assigned to fixed database roles. Also, this error requires a server permission called view server state. Database roles only control access inside a single database, not across the server.
Does the database owner role prevent message 10531?
Not by itself, because the database owner role works at the database level. A database owner can run maintenance tasks and even drop the database. Yet creating a plan guide from cache still requires the server state permission.
Related guides
In this post