SQL Server add sysadmin role

From WickyWiki

At some point I was no longer 'sysadmin' on my local SQL Server Express installation. The following was a solution.

Source:

Shut down SQL Server from services

net stop MSSQL$SQLEXPRESS

Open cmd-window (as admin) and run single-user mode as local admin with this command

"C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\Binn\sqlservr.exe" -m -s SQLEXPRESS

Other cmd-window (as admin):

sqlcmd -S .\SQLEXPRESS

Add your user to the 'sysadmin' group:

 sp_addsrvrolemember 'DOMAIN\user1', 'sysadmin'
 GO
 quit

Ctrl+C the single-user mode from the first cmd window to kill SQL Server.

Start services:

net start MSSQL$SQLEXPRESS

Log into Management Studio and the user you created should be listed under logins with the credential of "sysadmin."