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

Troubleshooting Guide: Error 3703 – Cannot Detach Database Because It Is Currently in Use

Why This Error Happens

Error 3703 occurs when SQL Server 2025 cannot detach a database because one or more active connections, open transactions, or processes are still referencing it. This commonly happens when applications maintain pooled connections that remain open even when idle, or when SQL Server Management Studio (SSMS) itself has an active query window pointed at the target database. Background processes such as Full-Text indexing, Replication, Mirroring, or the Query Store can also hold locks that prevent a clean detach operation.

Step-by-Step Resolution Guide

Step 1: Identify Active Connections to the Database

  • Open a new query window in SSMS connected to the master database (not the database you are trying to detach).
  • Run the following command to view active sessions: SELECT spid, status, hostname, program_name, loginame FROM sys.sysprocesses WHERE dbid = DB_ID('YourDatabaseName');
  • Note the spid (Session Process ID) values returned, as these represent the blocking connections.

Step 2: Force Single-User Mode to Clear Connections

  • Switch the database context to force out all other users before attempting the detach.
  • Execute: ALTER DATABASE YourDatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
  • This command immediately terminates all other transactions and connections to the specified database, rolling back any incomplete work.

Step 3: Disable Background Services and Retry Detach

  • Check if Full-Text Search or Replication is enabled on the database, as these background services often ignore standard connection kills.
  • Run sp_fulltext_database 'disable'; if Full-Text catalogs are present on the database.
  • Attempt the detach again using the stored procedure: EXEC sp_detach_db 'YourDatabaseName', 'true';

Step 4: Restart the SQL Server Service (If Needed)

  • If the lock persists after the above steps, specific system processes (like a hung backup job) may be holding the file handle at the OS level.
  • Open Services.msc on your Windows Server 2025 or Windows 11 machine.
  • Locate SQL Server (MSSQLSERVER), right-click, and select Restart to release any OS-level file locks.
  • Immediately re-run the sp_detach_db command before new connections can be established.

Alternative or Verification Steps

  • Verification: After running the detach command successfully, refresh the Databases folder in SSMS Object Explorer to confirm the database no longer appears in the list.
  • Alternative: If detaching is still blocked, use the GUI method instead: Right-click the database in SSMS, select Tasks > Detach, and check the “Drop Connections” checkbox in the dialog box before clicking OK.