Recover ‘sa’ password

Rédigé par Sozezzo - - Aucun commentaire

How reset the ‘sa’ password of SQL Server:

Plan A - If you have an account in sysadmin role then you can use SSMS or T-SQL:


GO
ALTER LOGIN [sa] WITH DEFAULT_DATABASE=[master]
GO
USE [master]
GO
ALTER LOGIN [sa] WITH PASSWORD=N'Pass1word$'
GO

 

Plan B- If you do not have an account in sysadmin role, but you are local administrator.

  1. Restart SQL Server in single-user mode;
  2. Open ‘sqlcmd’ and add yourself in the sysadmin role;
  3. Undo step 1;

That’s all pretty easy.

 

Step 1 : Restart SQL Server in single-user mode

 

Step 2: Open ‘sqlcmd’ and add yourself in the sysadmin role;

 

Or you can just execute this code to add yourself:


DECLARE @s AS NVARCHAR(200); SET @s='sp_addsrvrolemember '''+ SYSTEM_USER+''', ''sysadmin'';'; EXEC(@s);
GO
quit

 

Step 3: Undo step 1

Remove parameter ‘-m’ and restart SQL Server

Les commentaires sont fermés.