How to Fix SQL Server Error 15599 (Msg 15599)

Published
Length
3 min read

Luis Felipe Dias

All posts

You trigger sql server error 15599 when you try to set permissions or auditing on local temp objects. To fix this issue, remove permission statements from local temp tables or switch to permanent tables. Database scripts often create temporary staging tables during a session. When an engineer or script tries to grant or deny access on that local temp table, the engine returns message 15599. The database logs this event with severity level 10. It tells you that auditing and permissions cannot be

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 trigger sql server error 15599 when you try to set permissions or auditing on local temp objects. To fix this issue, remove permission statements from local temp tables or switch to permanent tables.

Database scripts often create temporary staging tables during a session. When an engineer or script tries to grant or deny access on that local temp table, the engine returns message 15599. The database logs this event with severity level 10. It tells you that auditing and permissions cannot be set on local temporary objects.

What causes sql server error 15599 in the database engine

Local temporary objects live only for the life of a single database session. Only the session that creates a local temp table can read or write to it. Other users on the same server cannot see or query that local table.

Because the engine already isolates local temp objects to one session, extra access rules make no sense. The engine blocks any command that tries to change permissions or auditing on these objects. When a deployment script runs permission changes against all tables, it fails if it hits a local temp table.

This issue also happens when teams copy scripts written for standard user tables. If they change the table name to a local temp object, the permission step triggers message 15599.

How to diagnose and fix the failure in production

First, search your stored procedures and deployment scripts for permission or audit statements. Look for places where the script creates a local temp object and then sets access rules. Remove those grant, deny, or revoke lines from the local temp object block.

If multiple users must share the data, do not use a local temp object. Create a regular user table inside your database instead. You can then manage access with standard database users and fixed roles.

A database user represents the identity of a login when it connects to a database. For people who need access to many databases on an instance, a SQL user with a login in master works well. For one or a few databases, an admin can enable contained databases and create a contained user with a password.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Once your data sits in a user table, assign the right fixed database roles. Note that you cannot change the permissions assigned to fixed database roles. Members of the datareader role can read all data from all user tables and views. Members of the datawriter role can add, delete, or change data in all user tables.

Avoid adding regular accounts to the database owner role just to bypass permission errors. The owner role can perform all maintenance actions and can even drop the database.

How to protect sensitive data without temp table grants

Teams sometimes try to lock down local temp tables because those tables hold sensitive rows. As message 15599 shows, object permissions do not work on local temp objects. Even on standard user tables, broad read roles let users see all column by default.

When you must block access to user tables, use the deny roles. The deny datareader role stops a user from reading data or metadata from any user table or view. The deny datawriter role stops a user from adding, changing, or deleting any data.

For finer control over sensitive columns, apply data masking in the query path. Dynamic masking rewrites matched fields in query results, such as emails, phone numbers, card numbers, and national IDs. This keeps sensitive fields safe during live sessions without breaking scripts with temp table permission errors.

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 exact message and severity for error 15599?

The database returns message 15599 at severity level 10. The official text states that auditing and permissions cannot be set on local temporary objects.

Who can read a local temporary table in SQL Server?

Only the current session that created the local temporary object can read or modify it. You do not need to set permissions to hide it from other logins.

How do I grant read access if I switch to a permanent user table?

Add the database user to the fixed datareader role using the alter role command. In Azure Synapse, use the add role member stored procedure instead.

The query runs. The emails stay hidden.