How to fix Error 6401 on Windows Server 2025 / Windows 11

Why This Error Happens

Error 6401 occurs when a ROLLBACK TRANSACTION or ROLLBACK WORK statement references a transaction or savepoint name that does not exist in the current session’s transaction stack. This typically happens due to a mismatch in nested transaction naming, a savepoint being created in a different connection/session scope, or application code that attempts to roll back after a transaction has already been committed or rolled back implicitly (such as after a severe error or connection reset). It can also surface when connection pooling reuses a session that has lost its transaction context.

Step-by-Step Resolution Guide

Step 1: Audit the Transaction and Savepoint Names in Code

  • Open the stored procedure, trigger, or application code referencing the failing transaction name.
  • Verify that SAVE TRANSACTION savepoint_name and ROLLBACK TRANSACTION savepoint_name use identical, case-sensitive string values.
  • Check for typos or dynamically generated names (e.g., via string concatenation) that may not match at runtime.

Step 2: Check for Premature Transaction Completion

  • Review @@TRANCOUNT before the rollback statement using PRINT @@TRANCOUNT for debugging.
  • Confirm that no prior COMMIT or ROLLBACK has already closed the transaction before the named rollback executes.
  • Inspect TRY...CATCH blocks to ensure error handling logic does not fire multiple rollback attempts on the same transaction.

Step 3: Validate Connection and Session Scope

  • Ensure the savepoint was created and is being rolled back within the exact same database connection/session (SPID).
  • Check Connection Pooling settings in your application’s connection string, located typically in web.config or appsettings.json, since pooled connections can reset transaction context unexpectedly.
  • If using MARS (Multiple Active Result Sets), verify that MultipleActiveResultSets=True in the connection string is not causing transaction state conflicts across batches.

Step 4: Review SQL Server Error Logs

  • Navigate to C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG on Windows Server 2025.
  • Search for Error 6401 timestamps and correlate them with the specific query or stored procedure execution to isolate the failing transaction block.
  • Enable Trace Flag 3604 temporarily in SQL Server Configuration Manager to output additional transaction diagnostics to the console if reproducing in a test environment.

Alternative or Verification Steps

  • Run the corrected stored procedure or script manually in SQL Server Management Studio (SSMS) and confirm @@TRANCOUNT returns to 0 after execution without triggering Error 6401.
  • If the issue persists intermittently, wrap rollback logic in a conditional check such as IF XACT_STATE() = -1 ROLLBACK TRANSACTION savepoint_name to prevent rollback attempts on already-doomed or completed transactions.