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

Troubleshooting Guide: SQL Server Error 5558 — “Database Should Be in Single-User Mode”

Why This Error Happens

Error 5558 occurs when you attempt to run an operation that requires exclusive access to a database—such as renaming it, restoring certain system objects, or executing specific ALTER DATABASE commands—while the database is still configured for MULTI_USER access mode. SQL Server 2025 enforces this restriction because these operations modify low-level metadata or file structures that could become corrupted if other sessions are simultaneously reading or writing to the database. This is a safeguard, not a bug, and it typically happens when a DBA forgets to change the access mode before running maintenance tasks.

Step-by-Step Resolution Guide

Step 1: Identify Active Connections to the Database

  • Open SQL Server Management Studio (SSMS) and connect to the instance.
  • Run the following query to check for existing sessions:
  SELECT session_id, login_name, status, host_name
  FROM sys.dm_exec_sessions
  WHERE database_id = DB_ID('YourDatabaseName');
  • Note any active session_id values other than your own; these must be terminated before proceeding.

Step 2: Set the Database to Single-User Mode

  • Execute the following T-SQL command, replacing YourDatabaseName with your actual database name:
  ALTER DATABASE YourDatabaseName
  SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
  • The ROLLBACK IMMEDIATE clause forcibly disconnects all other users and rolls back any open transactions, so ensure no critical uncommitted work is in progress.
  • If you receive a permissions error, confirm your login has the ALTER ANY DATABASE server-level permission or is a member of the sysadmin fixed server role.

Step 3: Perform the Required Maintenance Operation

  • Run the original command that triggered Error 5558 (e.g., sp_renamedb, DBCC CHECKDB with repair options, or restoring a .bak file).
  • Example for renaming a database:
  ALTER DATABASE YourDatabaseName MODIFY NAME = NewDatabaseName;
  • Monitor the SQL Server Error Log (located at C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG by default) for confirmation that the command completed successfully.

Step 4: Revert the Database to Multi-User Mode

  • Once the operation is complete, restore normal access for applications and users:
  ALTER DATABASE YourDatabaseName
  SET MULTI_USER;
  • Confirm no application connection strings are hardcoded to expect single-user mode, which could cause application-side timeouts during this window.

Alternative or Verification Steps

  • Verify the fix by querying sys.databases and checking the user_access_desc column (SELECT name, user_access_desc FROM sys.databases WHERE name = 'YourDatabaseName';)—it should read MULTI_USER after Step 4.
  • If ROLLBACK IMMEDIATE fails due to a stuck session, restart the SQL Server service via services.msc or net stop MSSQLSERVER && net start MSSQLSERVER as a last resort, then retry Steps 2–4.