How to Fix SQL Server Error 3988 (Msg 3988)
You get sql server error 3988 when a session starts a new transaction while other threads still run. You can fix it by closing open result sets before starting new transactions. This failure returns message 3988 at severity 16. The database engine blocks the new transaction because active work remains on the same connection. Teams often see this issue in apps that share one database session across tasks. Fixing the flow of queries in your app stops this conflict right away. What causes sql se
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 3988 when a session starts a new transaction while other threads still run. You can fix it by closing open result sets before starting new transactions.
This failure returns message 3988 at severity 16. The database engine blocks the new transaction because active work remains on the same connection. Teams often see this issue in apps that share one database session across tasks. Fixing the flow of queries in your app stops this conflict right away.
What causes sql server error 3988 in the engine
The official message for sql server error 3988 states that a new transaction is not allowed. It happens because there are other threads running in the session. A single session cannot start a fresh transaction while an unread query stream keeps the session active.
Many apps loop through rows from a select query and run an update inside the loop. If the app uses the same connection for both steps, the first query is still active. The database sees an active thread and rejects the new transaction request with severity 16.
Shared connection objects also trigger this error in web apps. When two background workers pick up the same session object, their commands collide. One worker reads data while the other tries to begin a transaction. The engine stops the second worker to protect data integrity inside that session.
How to diagnose and fix the session conflict safely
Start by finding which part of your app opens a transaction while a reader is active. Check your app logs for the exact query that failed with message 3988. Look at the code that runs right before that transaction starts.
The safest fix is to finish reading all rows before you start a transaction. Load the needed rows into memory first, and then close the reader object. Once the session has no active threads, you can run your transaction on that connection.
Kubernetes API Server Access + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
You can also use separate connections for reading data and writing changes. Let your read task use one connection from the pool. Open a second connection when you need to run a transaction. Never share a single connection object across multiple threads at the same time.
Keep database permissions tight during fixes
When engineers inspect production sessions to fix this bug, keep database permissions strict. Do not grant the db_owner fixed role just to debug an app error. Members of db_owner can change any setting and can even drop the database.
Instead, give debugging users a login in master or set up a contained database user. Place read-only reviewers in the db_datareader role so they can read user tables and views. If an engineer must test writes, add them to db_datawriter without granting full admin rights. You cannot change the permissions inside fixed roles, so pick the smallest role that fits.
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 does severity 16 mean for message 3988?
Severity 16 means the error comes from user code or query patterns, not a server crash. Your database is still healthy, and you can fix the issue in your app logic.
Can connection pooling cause this transaction error?
A normal connection pool will not cause this error by itself. The error happens when your code shares one active connection across multiple threads or open readers.
Do I need admin rights on the server to fix this error?
No, you do not need server admin rights or the db_owner role to fix it. You fix this issue in the client app by closing open readers before starting transactions.
Related guides
In this post