Start SQL Server in single-user or restricted mode

Starting SQL Server in single-user mode can be useful for performing maintenance tasks, such as restoring a master database, recovering from a disaster, or troubleshooting certain issues. Here’s how to start SQL Server in single-user mode:

Using SQL Server Configuration Manager

  1. Open SQL Server Configuration Manager:
  • You can find SQL Server Configuration Manager in the Start menu or by searching for it.
  1. Stop the SQL Server Service:
  • In SQL Server Configuration Manager, expand SQL Server Services.
  • Right-click on the SQL Server instance you want to start in single-user mode (e.g., SQL Server (MSSQLSERVER)) and select Stop.
  1. Set the SQL Server Startup Parameters:
  • Right-click on the SQL Server instance and select Properties.
  • Go to the Startup Parameters tab.
  • Add the parameter -m to the list. This tells SQL Server to start in single-user mode.
  • Click Add and then OK.
  1. Start the SQL Server Service:
  • Right-click on the SQL Server instance and select Start.

Using Command Prompt

  1. Stop the SQL Server Service:
  • Open Command Prompt with administrative privileges.
  • Run the following command to stop the SQL Server service:
    sh net stop MSSQLSERVER
    For a named instance, use:
    sh net stop MSSQL$InstanceName
  1. Start SQL Server in Single-User Mode:
  • Run the following command to start SQL Server in single-user mode:
    sh net start MSSQLSERVER /m
    For a named instance, use:
    sh net start MSSQL$InstanceName /m

Connecting to SQL Server in Single-User Mode

Once SQL Server is running in single-user mode, you can connect to it using SQL Server Management Studio (SSMS), sqlcmd, or any other SQL Server client. Only one connection is allowed, so make sure you are the only one connecting to the server.

Using SQL Server Management Studio (SSMS):

  1. Open SSMS.
  2. In the Connect to Server dialog, enter the server name.
  3. Click Connect.

Using sqlcmd:

  1. Open Command Prompt.
  2. Run the following command to connect to the server:

sqlcmd -S ServerName

Replace ServerName with the name of your SQL Server instance.

Performing Maintenance Tasks

While SQL Server is in single-user mode, you can perform various maintenance tasks, such as:

  • Restoring the master database:

RESTORE DATABASE master FROM DISK = 'C:\Backup\master.bak' WITH REPLACE;

  • Changing the server configuration or fixing issues:

ALTER DATABASE YourDatabase SET MULTI_USER;

Exiting Single-User Mode

After performing the necessary tasks, you can exit single-user mode by restarting SQL Server normally.

Using SQL Server Configuration Manager:

  1. Stop the SQL Server service.
  2. Remove the -m parameter from the startup parameters.
  3. Start the SQL Server service.

Using Command Prompt:

  1. Stop the SQL Server service:

net stop MSSQLSERVER

  1. Start the SQL Server service normally:

net start MSSQLSERVER

For a named instance, replace MSSQLSERVER with MSSQL$InstanceName.

Conclusion

Starting SQL Server in single-user mode is a powerful tool for performing critical maintenance tasks and troubleshooting. By following these steps, you can safely and effectively manage your SQL Server instance in single-user mode. Remember to revert to multi-user mode once your tasks are complete to ensure normal operation and accessibility for other users.

This entry was posted in MSSQLServer on by .
Unknown's avatar

About SandeepSingh

Hi, I am working in IT industry with having more than 15 year of experience, worked as an Oracle DBA with a Company and handling different databases like Oracle, SQL Server , DB2 etc Worked as a Development and Database Administrator.

Leave a Reply