0

为什么我不能更改登录 SA 凭据?

我已经使用本地管理员组中的登录名登录到 Windows 机器:

在此处输入图像描述

SSMS以管理员身份打开。

我已经连接到SQL SERVER使用的本地实例domain\myusername

(Microsoft SQL Server 2008 R2 (SP1) - 10.50.2811.0 (X64) 
    Apr  6 2012 01:59:29 
    Copyright (c) Microsoft Corporation
    Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)
)

当我尝试更改 login 的密码sa时,我得到:

在此处输入图像描述

我究竟做错了什么?

4

1 回答 1

0

尝试在命令提示符中执行以下命令(更改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.'"
于 2013-07-26T09:42:53.850 回答