If you've ever inherited a PC with SQL Server 2008 installed on it have probably hit the situation where you are a local admin but you can't access the SQL Server instance.This is because SQL Server 2008 unlike earlier versions of SQL Server doesn't by default give sysadmin access to the local Administrators group.
Here is a list of steps that will allow you to gain administrator access - provided you are a windows local admin.
Force SQL server to support mixed-mode
authentication
- Run REGEDIT
- Go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft
SQL Server\MSSQL10.SQLEXPRESS\MSSQLServer
Set "LoginMode" to 2.
(Source: http://support.microsoft.com/kb/285097) - Restart SQL Server.
Force SQL server to let you in temporarily
- Go to services.
- Stop SQL Server.
- Grab the SQL server
command-line (right click the service - properties). Mine is:
"C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Binn\sqlservr.exe" -sSQLEXPRESS - Open an administrative
command prompt.
- Run the command-line from
step 3, but add -m -c for single-user maintenance mode command-line.
- Open another administrative
command prompt.
- Run "sqlcmd
-S localhost\SQLEXPRESS" from that same directory (replace with
your server and instance name)
- Now you can do all the stuff
everyone told you to do that didn"t work. For example, to create a
hero user with administrative access:
CREATE LOGIN hero WITH PASSWORD="123", DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
EXEC sys.sp_addsrvrolemember @loginame = "hero", @rolename = "sysadmin"
GO - QUIT and close the
command-prompt
- Go to the SQL Server
command-line window and hit ctrl+C. It will prompt "Do you wish to
shutdown SQL Server (Y/N)?" and enter Y.
- Close the command-prompt
(Source: http://msdn.microsoft.com/en-us/library/dd207004.aspx)
Finally, login using your hero
- Restart the SQL Server
service
- Login using SQL Server
authentication as the user "hero" with password "123"
- *BAM* now you are in. Now
give yourself sysadmin access, etc, etc.