On numerous occasions after completing a SQL Server installation (2016,to 2019) I’ve noticed that the SA user account and the other specified sysadmin accounts all disappear from the server. This post will show you how to access the database again to re-add those users. It is important to note that this method will require downtime, so if it’s a case where your login is the only sysadmin account on the database and you’ve forgotten you password, to reset it the database will require a restart.
- Log on to the server that host the database.
- Go to the start menu, locate and run Sql Server Configuration Manager as administrator (right clicking, Select More > Run as Administrator)
- The Sql Server Configuration Manager Appears.
- In the left panel select SQL Server Services
- In the right panel right-click the instance (SQL SERVER (MSSQLSERVER) and select properties
- In the new window that appears select the startup parameters tab
- In the specify a startup parameter box enter -m and press add. -m puts the database in single user mode
- Click apply (you will be prompted to restart the instance)
- Click ok
- Back in the Sql Server Configuration Manager window right click the instance again and hit restart.
- Open the command prompt in administrator mode by going to the start menu, type in cmd, right click , more > run as administrator.
- In the new window that appears (cmd window) enter:
- You now have access to the database using the local administrator account on the server
- To reset the sa password or any other sysadmin password enter:
ALTER LOGIN [sa] WITH PASSWORD=N'Password' GO
- You can now close the command prompt
- In step 7 we placed the database in single-user mode before we can access the database we will need to take it out of this mode.
- Repeat steps 2 to 10, but for step 7 we are going to remove instead of adding the parameter by selecting -m and hitting the remove button.
- Open management studio and enter your new credentials
- Please see the gifs below for a working example
How To GIFs
This is only one of many solutions that a DBA can use to access a database that they are locked out of(Other solution: How to easily access SQL Server 2019 if locked out). It is important to note that there will be down time with this method, and DBAs must take that into consideration before attempting it. In another post we will cover how to access the database without incurring any data loss or down time. However this method is perfect for a newly installed instance where the sysadmin accounts have disappeared or the sysadmin password is forgotten. Check out our other articles How to add a new Named Instance in SQL Server and 5 free tips on how to keep SQL Server Database performing