// SQL Server error reference

SQL Server error 6401: No transaction or savepoint found

ROLLBACK TRANSACTION name named a savepoint or transaction that doesn't exist, often a misspelling or a savepoint that was never set.

Error number
6401
Severity
16
Category
Transactions and locking
Error message
Cannot roll back %.*ls. No transaction or savepoint of that name was found.

What it means

ROLLBACK TRANSACTION name rolls back to the savepoint (or outermost named transaction) with that name. If no savepoint or transaction of that name exists in the current transaction, SQL Server raises 6401. Rolling back to a savepoint doesn't end the transaction; only an unnamed ROLLBACK or the outermost name does.

Common causes

  • A typo in the savepoint name, or a SAVE TRANSACTION that was skipped by control flow.
  • Naming an inner BEGIN TRANSACTION name in ROLLBACK; only the outermost transaction's name or a savepoint name is valid.
  • The transaction was already rolled back by an earlier error.

How to fix it

  1. Set the savepoint before the work you may need to undo, and roll back to the same name.

    BEGIN TRANSACTION;
    SAVE TRANSACTION BeforeImport;
    -- work
    IF @@ERROR <> 0 ROLLBACK TRANSACTION BeforeImport;
    COMMIT TRANSACTION;
  2. Check XACT_STATE() first: if it's -1, only a full ROLLBACK is possible.

Related errors

More transactions and locking errors

The code and message text are from the Microsoft Database Engine events and errors reference. Browse the full SQL Server error list or search every database error.

// fewer errors, faster fixes

Work on SQL Server in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQL Server and the other databases you use.