Search This Blog

How to access a newly installed SQL Server 2008 R2 instance if you do not know the login and password

1.Open command prompt with Administrator
2.Run the following command prompt to stop SQL service:
       "net stop mssqlserver"
3.Now go to the directory where SQL server is installed.
   Run cd C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Binn
4.Now run the following command to start sql server in single user mode.
  sqlservr -m"SQLCMD"
  Note:- for named instance need to suppy the instancename after -s switch example: id instancename is SQL2008R2 then need to run sqlservr -m"SQLCMD" -sSQL2008R2
5.Now open another command prompt window with as Administrator and write command follwoing command
  SQLCMD
6.Run following two commands view sourceprint?
  CREATE LOGIN [testAdmin] WITH PASSWORD=N'test@1234', DEFAULT_DATABASE=[master];
  EXEC sys.sp_addsrvrolemember @loginame = N'testAdmin', @rolename = N'sysadmin';
  GO
  Press Enter.
7.Go back to first command window and press Ctrl+C to stop the SQL server and then type 'Y' for confirmation. This will stop the sql server.
8.Start SQL server again at services.msc
9.startup parameters need to specified this time.Now using SSMS, try to connect with
  "testAdmin" as user and "test@1234" as password.
10.Create your own logins
11.Drop testAdmin as it is not required any more.
Note: If you do not have SQL authentication enabled then you can try adding your windows user and replace setp-6 with below queries. Here <<DOMAIN\USERNAME>> is placeholder for your user name

view sourceprint?1.create login [<<DOMAIN\USERNAME>>] from windows; 
2.EXEC sys.sp_addsrvrolemember @loginame = N'<<DOMAIN\USERNAME>>', @rolename = N'sysadmin'; 
3.GO;