Monday 15 January 2018

How to recover SA password on Microsoft SQL Server


When you are using MS SQL Server in mixed mode, it is very important that you know your SA password.
There can be different reasons you lost the password
  1. Person who installed the SQL Server knows the password but has left the building.
  2. You did not write down the password in your password file
  3. Password file is lost
Steps to recover the SA password

Start SQL Server Configuration Manager

Stop the SQL services

Edit the properties of the SQL Service


Change the startup parameters of the SQL service by adding a –m; in front of the existing parameters


Start the SQL services. These are now running in Single User Mode. 

Start CMD on tthe SQL server
Start the SQLCMD command. Now you will see following screen


Now we create a new user. Enter following commands
CREATE LOGIN newlogin WITH PASSWORD = ‘XXXXXX′(Remember SQL server has default strong password policy
Go
Now this user is created
Now we grant the user a SYSADMIN roles using the same SQLCMD window.
sp_addsrvrolemember ‘newlogin’, ‘sysadmin’
go
Stop the SQL service again
Change the SQL service properties back to the default settings


Start the SQL service again and use the new created login (newlogin in my above example)
Go via the security panel to the properties and change the password of the SA account.


Now write down the new SA password.


How to transfer logins and passwords between instances of SQL Server:
http://support.microsoft.com/kb/246133
http://support.microsoft.com/kb/918992

No comments:

Post a Comment

PowerShell script to backup/restore procedures for Migrating each database

  Below is the PowerShell script that will implement backup/restore procedures for each database which we want to migrate to complete the mi...