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
dbouser (while allowing multiple dbo connections), use only:
ALTER DATABASE [YourDB] SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE;
(Note:DBO_USE_ONLYis generally paired withRESTRICTED_USER, notSINGLE_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_USERcommand to kick out other connections. - Once connected, if you specifically need
dborestrictions, you must first set the database back toMULTI_USERbefore applyingRESTRICTED_USERorDBO_USE_ONLY, asSINGLE_USERmode 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_USERand checking aDBO_USE_ONLYbox 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 eitherSINGLE_USERorRESTRICTED_USER/MULTI_USERas 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.mscon Windows Server 2025, then reapply only theSINGLE_USERoption to regain exclusive access before retrying your maintenance task.