1、验证一致性
select @@SERVERNAME
SELECT SERVERPROPERTY(‘MachineName‘)
修改windows主机名以后,使用上面命令查看时显示不一致,需要修复。
2、使用如下脚本执行并修复
DECLARE @server_name varchar(50);
set @server_name = (select @@SERVERNAME);
DECLARE @SERVER_PROPERTY varchar(50);
set @SERVER_PROPERTY = CONVERT(varchar(50),(SELECT SERVERPROPERTY(‘MachineName‘)));
exec sp_dropserver @server = @server_name,@droplogins = null ;
exec sp_addserver @[email protected]_PROPERTY, @local = ‘LOCAL‘, @duplicate_ok = null ;
DECLARE @login_server_name_cmd varchar(100);
DECLARE @LOGIN_SERVER_PROPERTY_CMD varchar(200);
DECLARE @LOGIN_SERVER_PROPERTY_RCMD varchar(200);
set @login_server_name_cmd=‘DROP LOGIN [‘[email protected]_name+‘\Administrator]‘
set @LOGIN_SERVER_PROPERTY_CMD=‘CREATE LOGIN [‘[email protected]_PROPERTY+‘\Administrator] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[简体中文]‘;
set @LOGIN_SERVER_PROPERTY_RCMD=‘master..sp_addsrvrolemember @loginame=[‘[email protected]_PROPERTY+‘\Administrator], @rolename = [sysadmin]‘
IF EXISTS (SELECT * FROM sys.server_principals WHERE name [email protected]_name+‘\Administrator‘)
exec (@login_server_name_cmd);
exec (@LOGIN_SERVER_PROPERTY_MD);
exec (@LOGIN_SERVER_PROPERTY_RCMD);
注意:对于sqlserver2008,请使用sa或其他具有sysadmin权限用户登陆执行。
3、重启sqlserver数据库生效
修windows主机名以后修复sqlserver实例名一致性