Friday, August 23, 2013

SQL Server Express - Adding sysadmin

I had a situation today where I needed to get into SQLEXPRESS. I was logged onto the machine as an Administrator, but SQLEXPRESS had been installed such that Builtin\Administrators was not a valid login with sysadmin server role. I found this post from Blipsalt that helped me:

http://social.msdn.microsoft.com/Forums/sqlserver/en-US/76fc84f9-437c-4e71-ba3d-3c9ae794a7c4/sql-express-2008-r2-create-database-permission-denied-in-database-master

1.  shut down SQL Server from services
2.  open cmd window (as admin) and run single-user mode as local admin with this command:
"c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Binn\sqlservr.exe" -m -s SQLEXPRESS
3.  open another cmd window (as admin)
4.  open sqlcmd:
sqlcmd -S .\SQLEXPRESS
Now add the sysadmin user:
a.  sp_addsrvrolemember 'domain\user', 'sysadmin'
b.  GO
5.  now Ctrl+C the single-user mode from the first cmd window to kill SQL Server.  Now restart it from services the normal way.  Log into Management Studio and the user you created should be listed under logins with the credential of "sysadmin."

No comments:

Post a Comment