266 SQL Origin: Data OSI layer 7 · Application Last updated 18 Nov 2026

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.

Exact message you may see 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
Seen on: SQL Server SQL

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

  1. Balance BEGIN/COMMIT on every path
  2. Wrap in TRY/CATCH with a guarded ROLLBACK
  3. Use savepoints for nested procedures

Detailed fix by platform

SQL

  1. IF @@TRANCOUNT = 0 BEGIN TRAN ELSE SAVE TRAN sp1;

How to diagnose

  1. Count before/after — Equal?
  2. Error path — Rolls back?
  3. 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:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

1205 — SQL Server Msg 1205: Transaction was deadlocked on lock resources and has been chosen as the deadlock victim (SQL)1205209 — SQL Server Msg 209: Ambiguous column name (SQL)20925P02 — ERROR: current transaction is aborted, commands ignored until end of transaction block (PostgreSQL)25P023902 — SQL Server Msg 3902: The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION (SQL)390240001 — ERROR: could not serialize access due to concurrent update (PostgreSQL)40001COMMIT — Changes disappear: transaction never committed (autocommit off, missing COMMIT) (SQL)COMMITcontention — Firestore: 10 ABORTED: Too much contention on these documents. Please try again. (Google Cloud / Firebase)contentionDeadlock — Deadlock found when trying to get lock; try restarting transaction (SQL)Deadlock266

Explore the map of this error Full error map →

🧠 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.