How to Fix SQL Server Error 3989 (Msg 3989)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get sql server error 3989 when a request lacks a valid transaction descriptor. You fix it by resetting the broken session and closing open result sets. The engine throws message 3989 at severity level 16 during bad transaction states. The exact message says a new request cannot start without a valid descriptor. This stops your app from running more queries on that active session. What causes sql server error 3989 in the database engine SQL Server tracks every active transaction with a un

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 3989 when a request lacks a valid transaction descriptor. You fix it by resetting the broken session and closing open result sets.

The engine throws message 3989 at severity level 16 during bad transaction states. The exact message says a new request cannot start without a valid descriptor. This stops your app from running more queries on that active session.

What causes sql server error 3989 in the database engine

SQL Server tracks every active transaction with a unique internal number. The client driver sends this descriptor number with each new query request. Sometimes the client app and the server lose sync over the network.

This sync loss often happens when a previous query fails or times out. The client driver might still hold the old transaction ID in memory. When the app sends the next command, the server rejects that old ID.

Connection pooling can also pass a dirty session to a new app thread. If the last thread left an unread result set, the state breaks. The new thread tries to start work, and the engine blocks it.

Drivers that run multiple batches on one connection also trigger this bug. If one batch aborts a transaction, the other batch holds a dead reference. The database engine sees the bad ID and returns severity 16.

How to diagnose and fix the failure in production

Start by checking your app logs for timeouts right before the error. A timeout cancels the query on the client, not on the server. The app must roll back and close the session after any timeout.

Make sure your code reads every row from a query before starting another. Unread rows leave the network buffer full and lock the transaction state. Closing the data reader frees the session for the next command.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Next, check how your app pool handles broken connections after an error. The pool should test and reset the session state before reuse. If a transaction fails, drop that connection instead of returning it.

When you check the server, use a safe read-only login. A database user is the identity of a login in a database. For access to many databases, use a SQL user with a master login. For one database, an admin can enable contained database users with passwords.

Do not use the owner role just to check live transaction states. Members of the owner role can drop the database and change all settings. Instead, add your debug user to the fixed data reader role. That role lets you read all user tables and views without risk.

How to prevent bad transaction descriptors in client apps

Keep your transactions short and never wait for user input inside them. Long transactions raise the chance of network drops and state errors. Run your reads outside the transaction block whenever your app logic allows.

Update your client data drivers to the latest stable release as well. Older drivers sometimes fail to clear the descriptor header after a batch error. A clean driver state stops message 3989 before it hits your database.

Separate your read queries from your heavy write transactions in the app. You can route read traffic to a user in the data reader role. You can even block writes on that user with the deny data writer role. This split keeps your write sessions clean and easy to manage.

Govern SQL Server queries and responses in flight

Table grants decide which SQL Server objects a caller may touch. They do not check query intent or rewrite sensitive values in results across every client and agent. By design, hoop.dev sits inline in the TDS wire protocol next to SQL Server as a sidecar for your SQL Server. On every production batch from an engineer or AI agent, hoop.dev decides to pass, mask, block, or hold it for approval.

With hoop.dev guardrails and hoop.dev data masking, banned statements are refused or held for review, matched sensitive fields in supported result columns are masked in memory, and each decision is logged. Check out the code on GitHub.

Frequently asked questions

What does severity 16 mean for message 3989?

Severity 16 means the error comes from user code or client state. The database engine is healthy, and only the current request failed.

Does clearing the connection pool fix this error?

Yes, clearing the pool drops the sessions that hold bad transaction IDs. New connections will start fresh with a clean state on the server.

Can database role permissions cause error 3989?

No, role permissions do not trigger a bad transaction descriptor error. Still, a permission error can abort a batch and leave a dirty session.

The query runs. The emails stay hidden.