Locked Out of SQL Server sa User – How to Recover

authenticationSecuritysql serverwindows-authentication

So I was trying to change some settings in my Microsoft SQL Server Management Studio 2019. I change the login mode from mixed (Windows and SQL authentication) to only Windows and now I am not able to login with my sa account and I don't have another account which has admin rights.

What should I do? Any suggestion will be highly appreciated.

Best Answer

There are two ways to handle this.

One option is to login to the windows machine as a local administrator, start SQL Server in single user mode (-m startup switch) and you will now be able to get into your SQL server as a sysadmin using Windows authentication.

The other option is to quite simply change back to mixed mode by modifying the registry in windows directly (not supported). On my machine, the registry path for a named instance (named "a") is: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL14.A\MSSQLServer. And the value for mixed authentication is LoginMode: 2.