As a result of some failure or operational
error, sometimes we may encounter a user who lost administrative privileges in
SQL Server. To make matters worse, often this was the only user with
administrative privileges on the database. And now, how to solve it?
Fortunately, there is a way to reactivate the
administrator privilege to this user, since this user is also a Windows
administrator user. Confirmed this hypothesis, let’s go to the steps to
re-enable the administrator privileges for this user in SQL Server:
- Log on to Windows with the user who lost access to SQL Server. Keep in mind that this user must have administrator privileges on Windows.
- Restart the service in SQL Server by
adding the “-mSQLCMD” parameter, using the SQL Server Configuration Manager.
This parameter allows access to SQL Server only through the SQLCMD:
- Connect to SQL Server through the
SQLCMD:
- Add the user login to the role “sysadmin”,
through the following command:ALTER SERVER ROLE [sysadmin] ADD MEMBER [<domain>\<login>];GO
- Remove the parameter “-mSQLCMD” of the SQL Server service startup.
- Restart the SQL Server service.
For more
information, see the articles below:
- Connect to SQL Server When System Administrators Are Locked Out: https://msdn.microsoft.com/en-us/library/dd207004.aspx
- ALTER SERVER ROLE (Transact-SQL): https://msdn.microsoft.com/en-us/library/ee677634.aspx