SQL Server Msg 266: Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements
A stored procedure or trigger exited with a different @@TRANCOUNT than it started with.
Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statementsThe transaction ended in the trigger. The batch has been abortedmismatching number of BEGIN and COMMIT statements Meaning
Every BEGIN TRAN needs exactly one COMMIT/ROLLBACK on all paths, including error paths. Use TRY/CATCH, avoid ROLLBACK inside nested procedures unless you manage savepoints, and check triggers (Msg 3609 "transaction ended in the trigger").
Common causes
- Missing COMMIT/ROLLBACK on an error path
- ROLLBACK inside a nested procedure
- Trigger rolling back the outer transaction
- Exception skipping the commit
- Unbalanced BEGIN/COMMIT
⚡ Quick fix
- Balance BEGIN/COMMIT on every path
- Wrap in TRY/CATCH with a guarded ROLLBACK
- Use savepoints for nested procedures
Detailed fix by platform
SQL
IF @@TRANCOUNT = 0 BEGIN TRAN ELSE SAVE TRAN sp1;
How to diagnose
- Count before/after — Equal?
- Error path — Rolls back?
- Trigger — Rolls back?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in SQL
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 18 Nov 2026