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

Troubleshooting Guide: Error 5066 – Conflicting Database Options (SINGLEUSER / DBOUSE_ONLY)

Why This Error Happens

This error occurs because SINGLE_USER and DBO_USE_ONLY are mutually exclusive database access options in SQL Server, and both cannot be applied in the same ALTER DATABASE statement or transaction. Typically, this happens when an administrator or an automated maintenance script attempts to restrict database access for maintenance tasks (like restores or integrity checks) but incorrectly chains both options together. Since SINGLE_USER already restricts access to one connection, SQL Server rejects the simultaneous request to also limit access strictly to the dbo user, resulting in Error 5066.

Step-by-Step Resolution Guide

Step 1: Identify the Conflicting Script or Command

  • Open SQL Server Management Studio (SSMS) on your Windows Server 2025 or Windows 11 machine.
  • Review the specific T-SQL script, Maintenance Plan, or Agent Job that triggered the error.
  • Look specifically for a statement structured similarly to: ALTER DATABASE [YourDB] SET SINGLE_USER, DBO_USE_ONLY WITH ROLLBACK IMMEDIATE;

Step 2: Correct the T-SQL Syntax

  • Remove one of the two conflicting options from the command. You must choose only one restriction mode per transaction.
  • If restricting to a single connection for maintenance, use only:
    ALTER DATABASE [YourDB] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
  • If restricting access to only the dbo user (while allowing multiple dbo connections), use only:
    ALTER DATABASE [YourDB] SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE;
    (Note: DBO_USE_ONLY is generally paired with RESTRICTED_USER, not SINGLE_USER.)

Step 3: Execute the Commands Sequentially (If Both States Are Required)

  • If your workflow genuinely requires moving through both states, execute them as separate, sequential statements rather than a single comma-separated list.
  • First, run the SINGLE_USER command to kick out other connections.
  • Once connected, if you specifically need dbo restrictions, you must first set the database back to MULTI_USER before applying RESTRICTED_USER or DBO_USE_ONLY, as SINGLE_USER mode already implies a stricter lockdown.

Step 4: Apply Changes via SQL Server Configuration Manager (If GUI-based)

  • If using the SSMS GUI (Properties > Options > State), ensure you are not toggling both the “Restrict Access” dropdown to SINGLE_USER and checking a DBO_USE_ONLY box simultaneously in a custom script generated by the GUI.
  • Click “Script” instead of “OK” to view the generated T-SQL and manually remove the redundant option before execution.

Alternative or Verification Steps

  • Verification: Run SELECT name, user_access_desc FROM sys.databases WHERE name = 'YourDB'; to confirm the current state is either SINGLE_USER or RESTRICTED_USER/MULTI_USER as intended, without conflicting flags.
  • Alternative: If the database is stuck in a transitional state due to a failed script, restart the SQL Server service via services.msc on Windows Server 2025, then reapply only the SINGLE_USER option to regain exclusive access before retrying your maintenance task.