Getting Started with ASP.NET MVC - Part 5: How to do programming with razor syntax
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.


Upload Image Close it
Select File

Welcome to my blog. I am working as Database lead at Synaptic Digital. Hope you find some interesting things here.
Browse by Tags · View All
BRH 17
SQL Server 15
#SQL Server 11
#BI 10
#TSQL 8
TSQL 8
BI 7
SSRS 6
#SQLServer 6
SSRS 2008R2 5

Archive · View All
January 2011 6
December 2010 5
May 2012 4
March 2011 4
January 2012 2
February 2011 2
November 2010 2
April 2012 1
April 2011 1
October 2010 1

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

Jul 20 2010 10:31AM by Chintak Chhapia   

Many time, colleagues come to me ask, they have setup SQL 2008 or SQL 2008 R2 for development or QA environment, but they don't know the login by which they can connect to server.  In SQL server 2005, SQL use to add group BUILTIN\Administrators to the sysadmin fixed server role, meaning that any local NT administrator is automatically a SQL Server's sysadmin. But 2008 onwards, Windows Group BUILTIN\Administrators is not included in the SQL Server sysadmin server role by default.   

To avoid this situation, we need to specify the SQL server administrator on "Database Engine Configuration" screen while setup sql server. But, sometime this step is missed or the IT guys set some odd password to SA user. The same question is also posted on  MSDN forum . One way to recover from this situation is to uninstall and re-install the sql server again. But, using the below mentioned steps we can create a new login

  1. Open command prompt.
  2. If you have default instance run following command on command prompt to stop SQL service: "net stop mssqlserver"
  3. Now go to the directory where SQL server is installed. In my case the directory is "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn". So need to run CD C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn.
  4. Now run the following command to start sql server in single user mode. As we have specified "SQLCMD", now only SQLCMD connection can be made.
    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 and write command SQLCMD. In case of connecting to named instance we need to supply server and instance name as with -S switch
  6. Run following two commands
    CREATE LOGIN [testAdmin] WITH PASSWORD=N'test@1234', DEFAULT_DATABASE=[master];
    EXEC sys.sp_addsrvrolemember @loginame = N'testAdmin', @rolename = N'sysadmin';
    GO
  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 and no startup parameters need to specified this time.
  9. 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

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

Update 08-Jan-2011:- Recently, I found the script that is useful in doing all this task. This script is available here.

Tags: new install, username passowrd unknown, SQL 2008 R2, #DBA, BRH,


Chintak Chhapia
58 · 4% · 860
3
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

2  Comments  

  • Hey, Chintak! Good one! Very useful. Sorry for reading this so late. Thanks, Nakul.

    commented on Aug 6 2010 1:58AM  .  Report Abuse This post is not formatted correctly
    Nakul Vachhrajani
    6 · 26% · 5867
  • Thanks, this was super and useful.

    commented on Feb 25 2012 3:53AM  .  Report Abuse This post is not formatted correctly
    Guru Samy
    19 · 9% · 2068

Your Comment


Sign Up or Login to post a comment.

"How to access a newly installed SQL Server 2008 R2 instance if you do not know the login and password" rated 5 out of 5 by 3 readers
How to access a newly installed SQL Server 2008 R2 instance if you do not know the login and password , 5.0 out of 5 based on 3 ratings
    Copyright © Beyondrelational.com Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising