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

Troubleshooting Guide: SQL Server Error 929 — “Unable to Close a Database That Is Not Currently Open”

Why This Error Happens

This error typically occurs when a session attempts to close a database context that SQL Server’s internal tracking already considers detached, often due to an out-of-sync connection pool or an abrupt session termination that left stale database handles in memory. It can also surface when multiple concurrent processes issue conflicting USE or connection-close commands against the same database, causing a race condition in SQL Server’s resource management layer. In rarer cases, this points to transient corruption in the system catalog views (like sys.databases) or a mismatch between the client driver’s cached state and the actual server-side session state.

Step-by-Step Resolution Guide

Step 1: Verify Database and Session State

  • Open SQL Server Management Studio (SSMS) and connect to the instance.
  • Run SELECT name, state_desc FROM sys.databases; to confirm the database is actually online and not in a RECOVERING, SUSPECT, or OFFLINE state.
  • Cross-check active sessions using SELECT * FROM sys.dm_exec_sessions WHERE database_id = DB_ID('YourDatabaseName'); to identify orphaned connections.

Step 2: Reset the Connection Pool and Application Session

  • On the client/application server (Windows Server 2025 or Windows 11), restart the application pool or service that maintains the SQL connection (e.g., via IIS Manager or the relevant Windows Service in services.msc).
  • If using ADO.NET or ODBC, ensure connection pooling is being cleared: force a SqlConnection.ClearPool() call or restart the application process to flush stale handles.
  • Confirm the connection string points to the correct, currently attached database name (check for typos or case-sensitivity issues).

Step 3: Restart the SQL Server Service

  • Open Services (services.msc) on Windows Server 2025.
  • Locate SQL Server (MSSQLSERVER) or your named instance, right-click, and select Restart.
  • Alternatively, run from an elevated PowerShell prompt:
  • Restart-Service -Name 'MSSQLSERVER' -Force
  • This clears any lingering internal session-to-database mappings causing the mismatch.

Step 4: Check for Corruption in System Catalogs

  • Run DBCC CHECKDB('YourDatabaseName') WITH NO_INFOMSGS, ALL_ERRORMSGS; to rule out catalog or page-level corruption.
  • If corruption is found, follow standard repair procedures (restore from backup is preferred over REPAIR_ALLOW_DATA_LOSS).

Step 5: Update SQL Server Cumulative Updates

  • Check Windows Update or the official Microsoft Download Center for the latest Cumulative Update (CU) for SQL Server 2025.
  • Install the update, as Error 929 has historically been linked to session-handling bugs patched in subsequent CU releases.

Alternative or Verification Steps

  • After applying fixes, reconnect the application and attempt the original operation that triggered Error 929; monitor the SQL Server Error Log (Management > SQL Server Logs in SSMS) for recurrence.
  • If the error persists, enable Extended Events to trace database_state_change events and capture the exact session ID and query triggering the close attempt for deeper root-cause analysis.