Skip to content

Instantly share code, notes, and snippets.

@joe-oli
Created May 7, 2023 11:30
Show Gist options
  • Save joe-oli/aaf596fcdaaf529aaa590499eb56a047 to your computer and use it in GitHub Desktop.
Save joe-oli/aaf596fcdaaf529aaa590499eb56a047 to your computer and use it in GitHub Desktop.
Recover SQL Server 'sa' password
#1 Change the DB to single-user mode;
e.g. in SQL Configuration Manager, SQL Server services / <Your Server> / Properties / Startup Parameters
-f (Add, Apply)
RESTART (or stop, start)
#2
C:\Users\Administrator>SQLCMD -H $localhost
1> CREATE LOGIN newSA WITH PASSWORD = 'Pass@123'
2> go
1> ALTER SERVER ROLE sysadmin ADD MEMBER newSA
2> go
#3 change to multi-user mode (i.e. remove -f parameter)
RESTART (or stop, start)
Then, you should be able to login as newSA in SSMS, and reset the pwd for 'sa'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment