尝试在命令提示符中执行以下命令(更改DOMAIN\login
为您的):
net stop MSSQLSERVER
net start MSSQLSERVER /mSQLCMD
sqlcmd -S . -Q "if not exists(select 1 from sys.server_principals where name='DOMAIN\login') CREATE LOGIN [DOMAIN\login] FROM WINDOWS;EXEC master..sp_addsrvrolemember @loginame = N'DOMAIN\login', @rolename = N'sysadmin'"
net stop MSSQLSERVER
net start MSSQLSERVER
sqlcmd -S . -Q "if exists(select 1 from fn_my_permissions(NULL, 'SERVER') where permission_name = 'CONTROL SERVER') print 'You are a sysadmin.'"
或者,如果您的 SqlServer 实例具有特定名称,例如sql2008
:
set instanceName=sql2008
net stop mssql$%instanceName%
net start mssql$%instanceName% /mSQLCMD
sqlcmd -S .\%instanceName% -Q "if not exists(select 1 from sys.server_principals where name='DOMAIN\login') CREATE LOGIN [DOMAIN\login] FROM WINDOWS;EXEC master..sp_addsrvrolemember @loginame = N'DOMAIN\login', @rolename = N'sysadmin'"
net stop mssql$%instanceName%
net start mssql$s%instanceName%
sqlcmd -S .\%instanceName% -Q "if exists(select 1 from fn_my_permissions(NULL, 'SERVER') where permission_name = 'CONTROL SERVER') print 'You are a sysadmin.'"