// SQL Server error reference

SQL Server error 3998: Uncommittable transaction rolled back

A batch ended while its transaction was in an uncommittable state (XACT_STATE() = -1), so SQL Server rolled the transaction back.

Error number
3998
Severity
16
Category
Transactions and locking
Error message
Uncommittable transaction is detected at the end of the batch. The transaction is rolled back.

What it means

If an error dooms a transaction and the batch finishes without the code rolling back, SQL Server rolls it back itself at the end of the batch and reports 3998. Any changes in that transaction are gone. It typically appears after a CATCH block that handled an error but didn't roll back.

Common causes

  • A TRY...CATCH that swallows an error inside a transaction with XACT_ABORT ON, leaving the doomed transaction open.
  • Errors that doom the transaction regardless of XACT_ABORT, handled without a rollback.

How to fix it

  1. Roll back in every CATCH block when XACT_STATE() isn't 0.

    BEGIN CATCH
        IF XACT_STATE() <> 0 ROLLBACK TRANSACTION;
        THROW;
    END CATCH
  2. Find the original error, which ERROR_MESSAGE() reports in the CATCH block, and fix it.

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.