How to Reset SQL Server Password in Single-user Mode
Forgot your SA password and can't connect to SQL Server? How to login to SA account after locked out of SQL Server? Luckily there is a backdoor in SQL Server that will help you gain sysadmin access to your SQL Server instance. Just start SQL Server in single-user mode and you can then create a new SQL account with sysadmin role. This hacking trick makes it possible to unlock SQL Server login without resetting the password of any existing account.
Reset SQL Server Password in Single-user Mode
- Launch SQL Server Configuration Manager. Stop your SQL Server instance if it is running.
Right-click on your SQL Server instance and select Properties.
In SQL Server 2014 or 2012, click Startup Parameters tab. Enter –m and then click Add.
If you've installed SQL Server 2008 (R2) or an earlier version, click Advanced tab and add -m; before existing value in Startup Parameters box, without any spaces.
- Save your changes and restart the SQL Server instance. This will start SQL Server in single-user mode.
- Open an elevated Command Prompt and use the SQLCMD command to connect to your SQL Server instance:
SQLCMD –S .\SQLEXPRESS
Replace SQLEXPRESS with the name of your SQL Server instance. Here we'll create a new login called "tom" and then add this account to the SA server role. Run this command:
CREATE LOGIN tom WITH PASSWORD='P@ssword123' GO SP_ADDSRVROLEMEMBER tom,'SYSADMIN' GO
For SQL Server 2012/2014 or newer, ALTER SERVER ROLE should be used instead of SP_ADDSRVROLEMEMBER as this system stored procedure will be removed in a future version of Microsoft SQL Server.
CREATE LOGIN tom WITH PASSWORD='P@ssword123' GO ALTER SERVER ROLE sysadmin ADD MEMBER tom GO
- Once you've successfully performed these steps, the next step is to stop your SQL Server instance. Remove the -m you've added in Startup Parameters.
- Start your SQL Server instance. Open the SQL Server Management Studio and you can login using the newly created "tom" account. You now have SA access to your SQL Server instance. You may now reset the SA password and take control of your SQL Server box.
However, if you can't access SQL Server in single-user mode or can't log on Windows as administrator, this method won't work. In that situation, you need to use the SQL Server Password Changer program which enables you to unlock / reset SQL Server SA password offline.