Troubleshooting Guide: Error 5064 – Database Changes Blocked in Single-User Mode
Why This Error Happens
This error occurs because the database is currently configured with ALTER DATABASE ... SET SINGLE_USER, which restricts access to only one connection at a time. When your session is not that single active connection—or when a previous session terminated without properly releasing the lock—SQL Server blocks any further state or option changes to protect data integrity. This is common after maintenance tasks like restoring a database, running DBCC CHECKDB with repair options, or renaming a database, where the single-user flag was never reset to MULTI_USER afterward.
Step-by-Step Resolution Guide
Step 1: Identify Active Connections to the Database
- Open SQL Server Management Studio (SSMS) or Azure Data Studio and connect to the instance.
- Run the following query to check current session usage:
SELECT session_id, login_name, status, program_name
FROM sys.dm_exec_sessions
WHERE database_id = DB_ID('YourDatabaseName');
- Note the
session_idof any connection currently locking the database.
Step 2: Terminate Conflicting Sessions
- If an orphaned session is holding the single-user slot, kill it using its session ID.
- Execute the kill command in a new query window:
KILL <session_id>;
- Ensure no other applications (like SSMS Object Explorer tabs) are silently holding open connections to the target database.
Step 3: Reset the Database to Multi-User Mode
- Open a new query window connected to the
masterdatabase (not the target database itself). - Run the following command to force the change and roll back any incomplete transactions:
ALTER DATABASE YourDatabaseName SET MULTI_USER WITH ROLLBACK IMMEDIATE;
- Confirm the command completes without returning Error 5064 again.
Step 4: Check for Windows Server Resource Locks
- On Windows Server 2025, verify that no antivirus or backup agent (like Windows Server Backup VSS writer) is locking the
.mdfor.ldffiles. - Navigate to
Task Manager > Detailsand ensuresqlservr.exedoes not have a hung child process preventing the state change. - Restart the SQL Server (MSSQLSERVER) service via
services.mscif the lock persists after the rollback command.
Alternative or Verification Steps
- Verify the Fix: Run
SELECT name, user_access_desc FROM sys.databases WHERE name = 'YourDatabaseName';to confirm theuser_access_desccolumn now readsMULTI_USER. - Alternative Fix: If the
ALTER DATABASEcommand hangs indefinitely, restart the SQL Server service entirely via PowerShell usingRestart-Service -Name 'MSSQLSERVER' -Force, which will clear all active single-user locks upon reboot.