In order to get sysadmin permissions on SQL Server, I did this:
- Shut down SQL Server Services
- Open a command line as Administrator
- Change to you SQL Server Binn dir
- cd "c:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn"
- Run SQL Server in single-user mode
- sqlservr.exe -m -s MSSQLSERVER
- Open a new command line as Administrator
- Connect to SQL Server
- sqlcmd -S .\ (or sqlcmd -S .\MSSQLSERVER)
- Execute commands
- 1> sp_addsrvrolemember 'domain\user', 'sysadmin'
- 2> GO
- CTRL+C in both windows to exit sessions
- Restart SQL Server Services
- PS: You may need to be quick connecting to SQL (step 6) after starting it in single-user mode (step 4), otherwise some other process may pick up the session (remember, obviously, only one connection will be allowed...we're running in single-user mode!). Not a bad idea to have both command line windows open and ready to click Enter.
You just made my day. After accidentally deleting the database owner account, and realizing that the sa account was disabled, I thought I was going to have a very long and painful day ahead of me. Thanks for saving me!
ReplyDelete