Skip to content

Lost access to SQL Server. Now what ?

In this blog we will explain what to do to regain the access to your SQL Server instance. Here is our scenario :
– You have by accident removed all logins in SQL Server instance
– Your sa account by security and best practice is disabled
– So no possibility to login with a sqlcmd or your SSMS (SQL Server Management Studio) tools

First thing first, take a deep breath and be calm.

Then here are the steps to regain your access to the SQL Server instance

1- Connect to your server where the SQL Server instance is installed (do a RDP connection)

2- Make sure your are administrator on this server. This is really important

3- Stop the SQL Server instance by using the SQL Server Configuration Manager.

4- Run powershell as administrator

5- Navigate to the folder where the SQL Server executable is located. The default location is "C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Binn" for SQL Server 2019

6- Type the following command and press Enter: (This command starts the SQL Server instance in single-user mode)
sqlservr.exe -m

7- Run another Powershell as administrator

8- Type the following command and press Enter: (This command will let you to connect to the instance)
sqlcmd -S localhost -E

9- Now all you need to do is to create a login with the sysadmin role
CREATE LOGIN [LIFESAVER] WITH PASSWORD = 'Pa$$word123456'
GO
ALTER SERVER ROLE [sysadmin] ADD MEMBER [LIFESAVER]
GO

Here we go, Now you can restart your instance and login with your login freshly created and then recreate your removed logins again.

enjoy 😀

Questions about your own setup? A dbi services consultant can look at your case.

Talk to an expert (opens in a new tab)


Let’s work together

Ready to operate at
the next level?

Tell us about your challenge. We’ll bring the depth, the expertise, and the Swiss precision.

Microsoft Team

Microsoft Team

Posts published under the Microsoft Team account are collective contributions by the dbi services Microsoft consultants. The practice covers SQL Server across its lifecycle, from installation, migration, and security to high availability with Always On and performance tuning, together with Azure data services and the Microsoft Business Intelligence stack, including Power BI. The team holds Microsoft certifications up to Expert level and operates customer platforms under service level agreements.View Author posts

263 posts since October 2011

Leave a Comment

Your email address will not be published. Required fields are marked *