How to Recover SA Password and Start SQL Server in Single User Mode

How to Recover SA Password and Start SQL Server in Single User Mode

Recover SA Password on Microsoft SQL Server


Introduction

This article applies to Microsoft SQL Server 2005, and Microsoft SQL Server 2008 at the time of this writing.

If you ever lost a SA password, you may have thought your only option is to reinstall SQL and re-attach to the DB’s. However, SQL server provides a much better disaster recovery method which preserves objects and data in the master DB. Members of the server’s Local Administrator’s group can access SQL server by starting it in single-user mode.

Steps (4 total)

1

Configure SQL Single-User Mode

– Open SQL Server Configuration Manager
– Stop the SQL Server Instance you need to recover the SA password
– Open the properties on the SQL Server Instance and click on the Advanced tab
– Change the Startup parameter by adding -m; at the begging of the line and click OK
– Start the SQL Service Instance

2

Use SQLCMD to add a Sysadmin Account

– Open the command prompt
– Run sqlcmd and press enter

sqlcmd -S server\instance

– Run a Transact-SQL (Below) command to add an existing account or a new account to the sysadmin server role. Replace DOMAIN\Username with the account you want to add. *NOTE: if you receive errors, I’ve listed some common issues at the end of this article.

EXEC sp_addsrvrolemember ‘DOMAIN\Username’, ‘sysadmin’;
GO

3 Un-configer SQL Single-User Mode

– Open SQL Server Configuration Manager
– Stop the SQL Server Instance
– Open the properties on the SQL Server Instance and click on the Advanced tab
– Change the Startup parameter by removing the -m; at the begging of the line and click OK
– Start the SQL Service Instance

4

Reset sa Password

– Open Microsoft SQL Server Management Studio and login with the account you added
– Under the DB, expand Security, then Logins
– Open the properties for the sa account, and reset the password

Conclusion

It’s that simple…. If you received an error connecting with SQLCMD it is most likely caused by the SQL Browser service not running or the named pipes not being enabled or incorrect. If the SQL Browser Service isn’t started, start it. If there is a specific instance name, try connecting to that instance (ie: sqlcmd -S tcp:localhost\instancename). SQLCMD is connecting through named pipes and the pipe name for the default instance is:

\\.\pipe\sql\query

If you need more direction on resolving this, check out my original article in the references which has a step by step fix with pictures

How to Start SQL Server in Single User Mode ?

Sometime, We caught in a situation where we need to run SQL server in single user mode. Issues like Master DB restore, Sysadmin locked out etc.

Steps to start SQL Server in Single User Mode :-

1) Stop SQL Server Services

2) Add [-m] startup parameter in SQL Services from configuration manager

Parameter [-m] Starts SQL Server instance in single-user mode. SQL Server in single-user mode can connect with single user only and did not start CHECKPOINT process. Starting SQL Server in single-user mode enables any member of the computer’s local Administrators group to connect to the instance of SQL Server as a member of the sysadmin fixed server role.

From SQL Server 2005 to SQL Server 2008 R2

From SQL Server 2012 onwards

3) Start SQL Services & SQL server will come online in single user mode. You can connect using SQLCMD & continue with desired operation

If you liked this post, do like on Facebook at http://www.facebook.com/mssqlfun

Reference : Rohit Garg (http://mssqlfun.com/)

Comments are closed.