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

Troubleshooting Guide: SQL Server Error 3101 — Exclusive Access Could Not Be Obtained

Why This Error Happens

Error 3101 occurs when SQL Server cannot gain exclusive access to a database because other active connections, sessions, or processes are still using it. This is common during operations that require exclusive locks, such as restoring a database, setting it to SINGLE_USER mode, dropping a database, or applying certain schema changes. The conflict typically arises from lingering user connections, open sessions in SQL Server Management Studio (SSMS), active application connection pools, or background processes like replication, mirroring, or the SQL Server Agent still referencing the database.

Step-by-Step Resolution Guide

Step 1: Identify Active Connections to the Database

  • Open SSMS and connect to the target SQL Server 2025 instance.
  • Run the following query to list all active sessions using the database:
  SELECT session_id, login_name, host_name, program_name, status
  FROM sys.dm_exec_sessions
  WHERE database_id = DB_ID('YourDatabaseName');
  • Note any session IDs returned — these are blocking exclusive access.

Step 2: Terminate Blocking Sessions

  • Kill each blocking session individually using:
  KILL <session_id>;
  • Alternatively, force the database into SINGLE_USER mode with immediate rollback to drop all connections at once:
  ALTER DATABASE [YourDatabaseName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
  • Ensure no scheduled SQL Server Agent jobs are configured to run against this database during the maintenance window.

Step 3: Check for External Application Connections

  • On Windows Server 2025 / Windows 11, open Task Manager or Services.msc and identify any application services (IIS, custom Windows Services, reporting tools) that maintain persistent connections to the database.
  • Stop these services temporarily:
  Stop-Service -Name "YourAppServiceName"
  • Check connection pooling settings in application config files (e.g., web.config or appsettings.json) and restart the application pool in IIS if necessary.

Step 4: Retry the Original Operation

  • Re-attempt the restore, detach, or schema change operation now that exclusive access should be available.
  • If performing a restore, use:
  RESTORE DATABASE [YourDatabaseName] FROM DISK = 'C:\Backups\YourFile.bak' WITH REPLACE;

Step 5: Set Database Back to Multi-User Mode

  • Once the operation completes successfully, restore normal access:
  ALTER DATABASE [YourDatabaseName] SET MULTI_USER;
  • Confirm the database status shows as “ONLINE” and “MULTI_USER” in SSMS under Database Properties.

Alternative or Verification Steps

  • Verify the fix by re-running the sys.dm_exec_sessions query from Step 1 — it should return zero rows for the target database before attempting exclusive operations again.
  • If the error persists, restart the SQL Server service entirely via services.msc or Restart-Service -Name "MSSQLSERVER" in PowerShell to forcibly clear all lingering connections (note: this will disconnect all users from the instance).