SQL Server Error 563: Fix the INSERT EXEC Transaction
In this article
Error 563 in SQL Server — "The transaction for the INSERT EXEC statement has been rolled back and cannot commit" — means the outer transaction that wrapped your INSERT ... EXEC was rolled back, so SQL Server has no choice but to abort the statement that fed data into the INSERT. It is almost never a problem with the INSERT itself. The INSERT EXEC was doing fine; something else in the same transaction failed, deadlocked, or was killed, and by the time your statement tried to finish, the transaction was already doomed. The fix is to find the real failing statement, stop calling INSERT ... EXEC inside a transaction that can be rolled back under you, and, where possible, replace it with a set-based alternative. Most of the steps below are diagnostic before they are corrective, because you cannot fix 563 without knowing what killed the transaction.
What You'll Need
- Access to SQL Server Management Studio or Azure Data Studio, plus permission to run
DBCC INPUTBUFFER, querysys.dm_exec_requestsand read the error log (sysadmin or a role with VIEW SERVER STATE helps). - The exact stored procedure or script that throws the error, including any outer
BEGIN TRAN/COMMITwrapper. - A non-production copy of the database and the data the proc touches, so you can reproduce without risk.
- An app-side or SQL Server error log that captures the earlier error — the one that rolled back the transaction is the one that matters.
Step-by-Step
- Reproduce it cheaply. Run the failing procedure in a test window with the same input parameters and the same transaction wrapping, if any. Use
SET XACT_ABORT OFFin your session unless production usesON— that setting changes which errors abort the batch, and it changes how 563 shows up. - Read the errors before 563, not just 563. In SSMS open the Messages tab; in a log, sort by time. Error 563 is a symptom. You are looking for a deadlock victim message (1205), a conversion or constraint failure, an arithmetic overflow, a permission error from the proc being called, or a general "transaction was deadlocked" note from the client library. That earlier message names the culprit.
- Check whether the error occurred inside the called procedure or outside it. Connect a trace or Extended Events session if you cannot see it. Capture
error_reportedfor error numbers 1205, 3621, 50000 and 547 alongsiderpc_completedandsql_batch_completed. The event sequence tells you which batch rolled the transaction back. - Look for
SET XACT_ABORT ONandTRY...CATCHmismatches. A common pattern is a procedure that doesINSERT ... EXECand wraps its work in a transaction, calls the child procedure, and the child fails a constraint. WithoutXACT_ABORT ON, only some errors are caught by TRY/CATCH; with it on, nearly all are. Either way, the INSERT EXEC can no longer commit. - Look for
ROLLBACKinside a nested procedure. If a called procedure hasROLLBACK TRANSACTIONwithout a savepoint, it unwinds the *outer* transaction entirely. SQL Server returns 563 on the INSERT EXEC that is still running, and the outer batch fails with 3998 ("uncommittable transaction") later. Search the proc chain for bareROLLBACKstatements. - Check for a
SEToption mismatch at execution time.INSERT ... EXECcannot run alongside a change of some connection settings after execution starts (for example, a client switchingARITHABORTorANSI_NULLSfrom a new session). If different clients call the proc with different SET options, isolate that by running it from a fresh SSMS query window and from your app's connection. - Confirm whether nested INSERT EXEC is involved. You cannot nest
INSERT ... EXEC— if procedure A doesINSERT ... EXEC procedureBand procedure B also doesINSERT ... EXEC, SQL Server errors. Check every level of the call stack for a second INSERT EXEC. The error usually surfaces as 8164 ("An INSERT EXEC statement cannot be nested") but the outer state can degrade into 563 when transactions are involved. - Run the child procedure on its own, with the same parameters. If it succeeds standalone and 563 appears only in the parent, the problem is transaction scope, not the child's logic. If it fails standalone, fix the child first.
- Restructure the fix. Options, in order of preference: (a) replace
INSERT ... EXECwith set-based SQL, so no dynamic execution is needed; (b) move the INSERT EXEC outside the outer transaction — commit the transaction, run the INSERT EXEC, then start a new one; (c) keep the call but remove bare ROLLBACKs and standardise SET options at the top of each proc; (d) if you cannot change schema, wrap the INSERT EXEC in a savepoint (SAVE TRANSACTION ins_exec_pt) and roll back to it if needed. - Test in both orders. Run the whole thing under concurrent load and without it. Error 563 is often a race: two sessions touching the same rows, one becomes the deadlock victim, the transaction is chosen for rollback, and the other session's INSERT EXEC fails with 563. If concurrency is the cause, review locking and indexes rather than the INSERT syntax.
- Deploy and verify. Deploy to staging, repeat the exact original repro, and check the error log for 563 and 1205. If you changed proc text, remember to drop and recreate if column metadata changed, or use
WITH RECOMPILEwhere parameter sniffing causes plan differences.
Common Mistakes
- Fixing the INSERT EXEC. The insert is fine. Look upstream for the error that rolled the transaction back. Most wasted time in 563 debugging is spent staring at the wrong statement.
- Ignoring the client library. Some drivers, including older ODBC and JDBC versions, log 563 after a deadlock and mask the actual SQL error reported to the app. Read the server-side error log, not only the app log.
- Using
BEGIN TRAN ... INSERT EXEC ... COMMITaround a procedure that already manages its own transaction. Nested transaction counters look harmless until a rollback happens, then the count is wrong or the whole outer transaction dies. - Assuming
XACT_ABORT OFFmeans errors are ignored. It means only some errors terminate the batch; the consequences of an uncommittable transaction are just as severe when they occur. - Adding an empty
CATCHblock that swallows the error without checkingXACT_STATE(). A CATCH cannot rescue a rolled-back transaction; you must inspectXACT_STATE() = -1to know if you can commit at all.
Tips
- At the top of every procedure with
INSERT ... EXEC, set bothSET NOCOUNT ONand the four ANSI-related options your client uses. Mismatched SET options between the client and the procedure are a classic source of hidden errors. - Use
SET XACT_ABORT ONconsistently, and addIF XACT_STATE() = -1 ROLLBACKin CATCH blocks. That gives you a controlled outcome instead of a broken INSERT EXEC. - Wherever possible, avoid
INSERT ... EXEC: it prevents SQL Server from using parallel plans and cannot be nested. Set-based orOPENJSON/XML alternatives are cleaner and faster. - Turn on Extended Events (not Profiler) for a short window in production to catch the deadlock graph. The deadlock XML names the victim and the other participant, which is the fastest path to the fix.
Troubleshooting
If you still see 563 after fixing what looks like the failing statement, check whether the proc you call via INSERT EXEC is itself called from a trigger, a SQL Agent job, or another proc with its own transaction. A second nested ROLLBACK can unwind further than expected. Run DBCC INPUTBUFFER(spid) against the session id while the error is live to capture the exact batch text. If the session is killed before you can catch it, use a server-side trace in staging with a filter on error 563 and the preceding error. If the problem appears only through the application, compare the client connection's SET options with those in SSMS using sys.dm_exec_sessions. If the transaction is genuinely required and unavoidable, restructure so INSERT EXEC runs first and the transaction starts after it, or replace it with a table-valued parameter or temporary table populated by set-based code.
Frequently Asked Questions
What does error 563 actually mean?
It means the transaction under which the INSERT EXEC statement was executing has been rolled back — typically by a deadlock, a fatal error, or a bare ROLLBACK in a called procedure — so the statement cannot commit. The issue is the transaction, not the INSERT syntax.
Will restarting SQL Server fix it?
No. It may clear a stuck session temporarily, but the underlying trigger (deadlock, error, transaction scope) will cause the same failure again. Fix the cause.
Can I catch 563 in a TRY/CATCH block?
Yes, but the transaction is already uncommittable at that point. Check XACT_STATE(); if it returns -1, roll back and retry from a fresh transaction, because you cannot commit.
Does SET XACT_ABORT ON cause error 563?
It can make it more likely that a run-time error terminates the batch and rolls the transaction back, which is when 563 appears on INSERT EXEC. For procedures that manage their own transactions, keeping XACT_ABORT ON with correct CATCH handling is still the safer pattern.
Is a nested INSERT EXEC the cause?
It often is. SQL Server does not allow INSERT ... EXEC inside another INSERT ... EXEC, so restructure the code to avoid nesting — a common source of chain errors that can surface as 563 in a transaction.
How do I stop it recurring?
Find the original error (deadlock, constraint, or ROLLBACK), fix or handle it at its source, and reduce reliance on INSERT EXEC in the first place.