only My site

Saturday, September 1, 2012

SQL Server recover the "sa" password


We often forget password or sometimes we may remove the sysadmin role for the sa user. This will make us struck in doing administration tasks. To overcome this we need to execute the following commands in SQL Command prompt. 

Step - 1:
Start SQL Server Instance in Single User Mode. How to do click here
Step - 2:

Open a command prompt (Start -> Run -> cmd)
osql -E -S .\SQLEXPRESS_or_SQLInstanceName
exec sp_password @new='NEWPASSWORD', @loginame='sa'
go
alter login sa enablegoexit 
Solution - 2

Change SQL Server Password with the Query Windows in Management Studio. We need to use the Windows authentication to login to the Management studio.
    • Step 1. Open SQL Server Management Studio
    • Step 2. Open a new query
    • Step 3. Type the follow commands and excute:
      GO
      ALTER LOGIN [sa] WITH DEFAULT_DATABASE=[master]
      GO
      USE [master]
      GO
      ALTER LOGIN [sa] WITH PASSWORD=N’NewPassword’ MUST_CHANGE
      GO

No comments: