Hello,
Welcome to the Microsoft Community. Thank you for supporting Microsoft products.
You’re running into a common frustration with SQL Server’s single-user mode: it’s very easy for something else (often an automated service or tool) to grab the single available connection before you can. Here’s what’s happening and how you can fix it: Why this happens
- Single-user mode allows only one connection to the SQL Server instance.
- SQL Server Management Studio (SSMS), SQL Server Agent, SQL Server Integration Services, and even monitoring tools can all try to connect automatically, often grabbing the single slot before you do.
- Object Explorer in SSMS can use multiple connections, which will also block you.
How to reliably connect in single-user mode 1. Stop ALL SQL-related services
- Stop SQL Server Agent, SQL Server Integration Services, and any other SQL-related services except the main SQL Server service.
- You can do this in Services.msc or via command line:
net stop SQLSERVERAGENT
net stop MsDtsServer
net stop MSSQLSERVER
2. Make sure nothing else is connecting
- Close SSMS and any other tool that might try to connect (including monitoring/backup tools).
- Disconnect your network if possible, to prevent remote connections.
3. Start SQL Server in single-user mode with a specific client
- Open a Command Prompt as Administrator.
- Start SQL Server in single-user mode and restrict the connection to a specific tool (e.g., sqlcmd):
net start MSSQLSERVER /m"sqlcmd"
- For a named instance, use:
net start MSSQL$InstanceName /m"sqlcmd"
- This restricts the single connection to only sqlcmd clients.
4. Connect using sqlcmd
- In the same Command Prompt, run:
sqlcmd -S localhost
- If using a named instance: sqlcmd -S localhost\InstanceName
5. Add your account to sysadmin
- Once connected, run:
CREATE LOGIN [YourDomain\YourUser] FROM WINDOWS;
EXEC sp_addsrvrolemember 'YourDomain\YourUser', 'sysadmin';
GO
- Or, if your login already exists, just run the second line.
6. Stop and restart SQL Server normally
- After you’re done, stop SQL Server and restart it without /m.
Troubleshooting tips
- If you still get the error, something else is connecting first. Double-check that all SQL tools and services are closed/stopped.
- Don’t use SSMS to connect in single-user mode unless you use the /m"Microsoft SQL Server Management Studio - Query" switch (but even then, SSMS’s Object Explorer can open multiple connections).
- If you need to use SSMS, start SQL Server with:
net start MSSQLSERVER /m"Microsoft SQL Server Management Studio - Query"
Then, open only a single query window (not Object Explorer).
References
Microsoft Docs: Start SQL Server in Single-User Mode
How to: Connect to SQL Server When System Administrators Are Locked Out
Sincerely,
Nam-D - MSFT | Microsoft Community Support Specialist.