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

Troubleshooting Guide: Error 3917 – Session Bound to Transaction Context Already in Use

Why This Error Happens

Error 3917 occurs when a session attempts to run a new batch or statement while a transaction on that same session is already active and bound to another concurrent operation, typically caused by application code that fails to properly commit, rollback, or close a transaction before issuing new commands. This is commonly seen in multi-threaded applications or ORM frameworks that share a single connection object across threads without proper synchronization, or when MARS (Multiple Active Result Sets) is not enabled but the application attempts concurrent operations on the same connection. Occasionally, this can also result from an abruptly terminated client connection that leaves a “ghost” transaction bound to the session on the SQL Server 2025 engine side.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Session and Transaction

  • Open SQL Server Management Studio (SSMS) and connect to the instance.
  • Run the following query to find sessions with open transactions: SELECT session_id, transaction_id, is_user_transaction FROM sys.dm_tran_session_transactions WHERE is_user_transaction = 1;
  • Cross-reference the session_id with sys.dm_exec_requests to see if the session is blocked or sleeping while holding an open transaction.

Step 2: Enable Multiple Active Result Sets (MARS) if Required

  • If your application architecture requires running multiple batches on a single connection concurrently, navigate to your connection string configuration file (e.g., web.config or appsettings.json).
  • Add or modify the parameter: MultipleActiveResultSets=True;
  • Restart the application pool or service in IIS/Windows Server 2025 to apply the new connection string settings.

Step 3: Audit Application Code for Transaction Scope Leaks

  • Review the application source code for TransactionScope or SqlTransaction objects that are not wrapped in a try-finally or using block.
  • Ensure every BEGIN TRANSACTION has a corresponding COMMIT or ROLLBACK in all code paths, including exception handlers.
  • Check for recursive stored procedure calls that might be opening a second transaction on a connection already committed to a specific task.

Step 4: Terminate the Stuck Session (If Immediate Resolution is Needed)

  • If the session is confirmed to be an orphaned “ghost” connection and not currently processing critical data, you may need to clear it manually.
  • Execute the kill command using the session ID identified in Step 1: KILL <session_id>;
  • Monitor the sys.dm_exec_sessions view to confirm the session has been successfully terminated and resources have been released.

Alternative or Verification Steps

  • Verification: Re-run the original query or batch that triggered the error. If successful, check sys.dm_tran_active_transactions to confirm no orphaned transactions remain active for that specific login.
  • Alternative Fix: If the issue persists across a specific linked server query, verify that SET XACT_ABORT ON is configured at the top of your stored procedures to ensure any error automatically rolls back the entire transaction rather than leaving it “in use.”