Forgot your SA password and can't connect to SQL Server? How to login
to SA account after locked out of SQL Server? Start SQL Server in single-user mode and you can reset SQL Server password easily. This hacking trick
makes it possible to unlock SQL Server login without resetting the
password of any existing account.
How to Recover SA 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
- 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.