3 Ways to Reset SA User Password in SQL Server

Table of contents:

3 Ways to Reset SA User Password in SQL Server
3 Ways to Reset SA User Password in SQL Server
Anonim

This article shows you how to recover the forgotten password of the System Administrator user (known simply as SA) of an instance of Microsoft SQL Server. You can solve this problem in several ways: using the "Windows Authentication" authentication method, using the "Command Prompt", or using the "single user" mode.

Steps

Method 1 of 3: Use Windows Authentication

Reset SA Password in Sql Server Step 1
Reset SA Password in Sql Server Step 1

Step 1. Understand how this method works

If you have enabled the use of Windows authentication, you will be able to access the server without the need to enter any password. After logging in, you will be able to change the password of the SQL Server SA account very easily.

If the "Windows Authentication" authentication mode is not enabled, you can change the password using the "single user" mode or the "Command Prompt"

Reset SA Password in Sql Server Step 2
Reset SA Password in Sql Server Step 2

Step 2. Make sure you have installed the "SQL Server Management Studio" program, known simply as SSMS

It is a graphical user interface that allows you to manage various aspects of the configuration of a Microsoft SQL Server rather than having to use the "Command Prompt". If you haven't installed SQL Server Management Studio on your server yet, follow these instructions:

  • Access this web page using your computer browser;
  • Click the link Download SQL Server Management Studio 17.9.1;
  • At the end of the download, double-click on the program installation file;
  • Follow the instructions to be able to install SSMS on your computer.
Reset SA Password in Sql Server Step 3
Reset SA Password in Sql Server Step 3

Step 3. Start the SQL Server Management Studio program

Type sql server management studio keywords in the "Start" menu, then click the icon Microsoft SQL Server Management Studio 17 appeared at the top of the results list.

Reset SA Password in Sql Server Step 4
Reset SA Password in Sql Server Step 4

Step 4. Select the correct authentication method

Click the "Authentication" drop-down menu, then click the entry Windows authentication.

Reset SA Password in Sql Server Step 5
Reset SA Password in Sql Server Step 5

Step 5. Click the Connect button

It is located in the lower right part of the dialog box. If the "Windows Authentication" mode allows you to log into SQL Server with your user account, the server administration dashboard will be displayed.

Reset SA Password in Sql Server Step 6
Reset SA Password in Sql Server Step 6

Step 6. Expand the SQL Server instance folder

If a series of folders is not visible in the left pane of the SQL Server Management Studio GUI, click on the small icon to the left of the server name to view all related information

Reset SA Password in Sql Server Step 7
Reset SA Password in Sql Server Step 7

Step 7. Go to the "Security" folder

It is listed under the Microsoft SQL Server instance name.

Reset SA Password in Sql Server Step 8
Reset SA Password in Sql Server Step 8

Step 8. Open the "Login Accounts" folder

It is one of the items contained in the "Security" folder.

Reset SA Password in Sql Server Step 9
Reset SA Password in Sql Server Step 9

Step 9. Double-click the sa account

It is displayed at the bottom of the list of items that appeared under the "Login Accounts" folder. This will bring up the Microsoft SQL Server System Administrator account properties window.

Reset SA Password in Sql Server Step 10
Reset SA Password in Sql Server Step 10

Step 10. Set a new password

Type the new login password into the "Password" and "Confirm password" text fields at the top of the dialog box that appears.

Reset SA Password in Sql Server Step 11
Reset SA Password in Sql Server Step 11

Step 11. Click the OK button

It is located at the bottom of the window. This will cause the new password to be stored and applied and the SA account properties window will be closed.

Method 2 of 3: Use Single User Mode

Reset SA Password in Sql Server Step 12
Reset SA Password in Sql Server Step 12

Step 1. Understand how this method works

Even if you have locked out access to the only existing account using the "Command Prompt", you will still be able to create a new user and assign him the access rights of the SQL Server SA account. After performing this step you will be able to use the new user to connect to the SQL Server instance and change the password of the SA user.

Reset SA Password in Sql Server Step 13
Reset SA Password in Sql Server Step 13

Step 2. Make sure you have installed the "SQL Server Management Studio" program known simply as SSMS

It is a graphical user interface that allows you to manage various aspects of the configuration of a Microsoft SQL Server rather than having to use the "Command Prompt". If you haven't installed SQL Server Management Studio on your server yet, follow these instructions:

  • Access this web page using your computer browser;
  • Click the link Download SQL Server Management Studio 17.9.1;
  • At the end of the download, double click on the program installation file;
  • Follow the instructions to be able to install SSMS on your computer.
Reset SA Password in Sql Server Step 14
Reset SA Password in Sql Server Step 14

Step 3. Launch the "Command Prompt" in system administrator mode

Access the menu Start clicking the icon

Windowsstart
Windowsstart

then follow these instructions:

  • Type in the keywords command prompt;
  • Click the Command Prompt

    Windowscmd1
    Windowscmd1

    with the right button of the muse;

  • Click the entry Run as administrator;
  • Click on the button Yup when required.
Reset SA Password in Sql Server Step 15
Reset SA Password in Sql Server Step 15

Step 4. Stop running the SQL Server instance

Type the command net stop MSSQLSERVER in the "Command Prompt" window and press the Enter button. This will cause the SQL Server service to be stopped.

Reset SA Password in Sql Server Step 16
Reset SA Password in Sql Server Step 16

Step 5. Restart the SQL Server in "single user" mode

Type the command net start MSSQLSERVER -m "SQLCMD" and press the Enter key;

You will not see any notification that the SQL Server was started in "single user" mode, but the sentence "The SQL Server service has started successfully" should appear

Reset SA Password in Sql Server Step 17
Reset SA Password in Sql Server Step 17

Step 6. Connect to the SQL Server

Type the sqlcmd command and press the Enter key. The SQL server command line will be displayed.

Reset SA Password in Sql Server Step 18
Reset SA Password in Sql Server Step 18

Step 7. Create a new user and a new password

Use the SQL command line that appeared and the following statements:

  • Type the command CREATE LOGIN [name] WITH PASSWORD = '[pwd]', where the parameter "[name]" represents the name of the new account and the parameter "[pwd]" the relative access password;
  • Press the Enter key;
  • Type the GO command and press the Enter key.
Reset SA Password in Sql Server Step 19
Reset SA Password in Sql Server Step 19

Step 8. Add the new user to the SQL Server "System Administrator" group

Type the command SP_ADDSRVROLEMEMBER [name], 'SYSADMIN', where the parameter "[name]" represents the name of the new account just created, press the Enter key, type the GO command and press the Enter key again.

Reset SA Password in Sql Server Step 20
Reset SA Password in Sql Server Step 20

Step 9. Close the SQL Server Command Console

Type the command exit and press the Enter key.

Reset SA Password in Sql Server Step 21
Reset SA Password in Sql Server Step 21

Step 10. Restart the SQL Server instance service in normal mode

Run the command net stop MSSQLSERVER && net start MSSQLSERVER and press the Enter key.

The "SQL Server service has started successfully" message should appear again. At this point you can close the "Command Prompt" window

Reset SA Password in Sql Server Step 22
Reset SA Password in Sql Server Step 22

Step 11. Start the SQL Server Management Studio program

Type sql server management studio keywords in the "Start" menu, then click the icon Microsoft SQL Server Management Studio 17 appeared at the top of the results list.

Reset SA Password in Sql Server Step 23
Reset SA Password in Sql Server Step 23

Step 12. Select the correct authentication method

Click the "Authentication" drop-down menu, then click the entry SQL Server authentication.

Reset SA Password in Sql Server Step 24
Reset SA Password in Sql Server Step 24

Step 13. Log in with the credentials of the new user you just created

Click the "Login" drop-down menu and click the user name to use.

Reset SA Password in Sql Server Step 25
Reset SA Password in Sql Server Step 25

Step 14. Enter your password

Type in the "Password" text field at the bottom of the window.

Reset SA Password in Sql Server Step 26
Reset SA Password in Sql Server Step 26

Step 15. Click the Connect button

It is located in the lower right part of the dialog box. If you entered the correct username and password, the server administration dashboard will be displayed.

Reset SA Password in Sql Server Step 27
Reset SA Password in Sql Server Step 27

Step 16. Expand the SQL Server instance folder

If a series of folders is not visible in the left pane of the SQL Server Management Studio GUI, click on the small icon to the left of the server name to view all related information

Reset SA Password in Sql Server Step 28
Reset SA Password in Sql Server Step 28

Step 17. Go to the "Security" folder

It is listed under the Microsoft SQL Server instance name.

Reset SA Password in Sql Server Step 29
Reset SA Password in Sql Server Step 29

Step 18. Open the "Logins" folder

It is one of the items contained in the "Security" folder.

Reset SA Password in Sql Server Step 30
Reset SA Password in Sql Server Step 30

Step 19. Double-click the sa account

It is displayed at the bottom of the list of items that appeared under the "Login Accounts" folder. This will bring up the Microsoft SQL Server System Administrator account properties window.

Reset SA Password in Sql Server Step 31
Reset SA Password in Sql Server Step 31

Step 20. Set a new password

Type the new login password into the "Password" and "Confirm password" text fields at the top of the dialog box that appears.

Reset SA Password in Sql Server Step 32
Reset SA Password in Sql Server Step 32

Step 21. Click the OK button

It is located at the bottom of the window. This will cause the new password to be stored and applied and the SA account properties window will be closed.

Method 3 of 3: Use the Command Prompt

Reset SA Password in Sql Server Step 33
Reset SA Password in Sql Server Step 33

Step 1. Access the "Start" menu by clicking the icon

Windowsstart
Windowsstart

It features the Windows logo and is located in the lower left corner of the desktop. Alternatively, press the ⊞ Win key on your keyboard.

Reset SA Password in Sql Server Step 34
Reset SA Password in Sql Server Step 34

Step 2. Search for "Command Prompt"

Type the keywords command prompt into the "Start" menu, then wait for the "Command Prompt" icon to appear.

Reset SA Password in Sql Server Step 35
Reset SA Password in Sql Server Step 35

Step 3. Click the Command Prompt icon

Windowscmd1
Windowscmd1

with the right mouse button.

A context menu will be displayed.

Reset SA Password in Sql Server Step 36
Reset SA Password in Sql Server Step 36

Step 4. Click Run as administrator

It is one of the options listed in the menu that appeared.

Reset SA Password in Sql Server Step 37
Reset SA Password in Sql Server Step 37

Step 5. Click the Yes button when prompted

This will confirm your action and the "Command Prompt" window will be displayed in system administrator mode.

Reset SA Password in Sql Server Step 38
Reset SA Password in Sql Server Step 38

Step 6. Enter the first command to execute

Type the command osql -L and press the Enter key.

Reset SA Password in Sql Server Step 39
Reset SA Password in Sql Server Step 39

Step 7. Enter the next command by adding the SQL Server name

Type the command OSQL -S [server] -E, where the "[server]" parameter should be replaced with the instance name of the SQL Server server, then press the Enter key.

Reset SA Password in Sql Server Step 40
Reset SA Password in Sql Server Step 40

Step 8. Create a new security password for the SA account

Type the command EXEC sp_password NULL, '[pwd]', 'sa', where the parameter "[pwd]" should be replaced with the password you want to use, then press the Enter key.

For example, if you want to set the new password "rutabaga123", you will need to execute this command EXEC sp_password NULL, 'rutabaga123', 'sa' within the "Command Prompt" window

Reset SA Password in Sql Server Step 41
Reset SA Password in Sql Server Step 41

Step 9. Run the command

Type the GO command and press the Enter key. At this point type the command exit and press the Enter key to close the OSQL command console.

Reset SA Password in Sql Server Step 42
Reset SA Password in Sql Server Step 42

Step 10. Try to log in to the SQL Server using your SA account credentials

If you are able to login to the server, it means that the security password has been changed successfully.

Recommended: