20 September 2012

How to make yourself MSSQL admin

There is a good chance, that you run into a Microsoft SQL Server, where you don’t have administrative access. This can be happen when SQL is installed using another user account and this account is deleted afterwards.

First of all you need to stop SQL service (it can stop other SQL services also):

image

Then look at the properties of the service. Copy and paste the path to executable to administrative command prompt:

imageimage

Add to the command line "-mSQLCMD" and press Enter. This will run SQL server in interactive and single user mode and allows only sqlcmd to be launched.

image

At a different administrative command prompt run sqlcmd. If it fails with “Only one administrator…” error, then block SQL port using Windows Firewall and try again starting the service manually in single user mode. If it fails with “Token-based server access validation failed with an infrastructure error”, then you are not in administrative command prompt

image

When you succeed running sqlcmd, type two commands:

sp_addsrvrolemember 'domain\user', 'sysadmin'
go

image

Now your account domain\user is an administrator of this SQL server.

To close open command prompt windows gracefully, type quit and press Enter in sqlcmd prompt and press CTRL+C on sql server prompt and press Y.

Also remember to start services.

No comments:

Post a Comment