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 @server=@SERVER_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 ['+@server_name+'\Administrator]' set @LOGIN_SERVER_PROPERTY_CMD='CREATE LOGIN ['+@SERVER_PROPERTY+'\Administrator] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[简体中文]'; set @LOGIN_SERVER_PROPERTY_RCMD='master..sp_addsrvrolemember @loginame=['+@SERVER_PROPERTY+'\Administrator], @rolename = [sysadmin]' IF EXISTS (SELECT * FROM sys.server_principals WHERE name =@server_name+'\Administrator') exec (@login_server_name_cmd); exec (@LOGIN_SERVER_PROPERTY_CMD); exec (@LOGIN_SERVER_PROPERTY_RCMD);
注意:对于sqlserver2008,请使用sa或其他具有sysadmin权限用户登陆执行。
3、重启sqlserver数据库生效
SQL Server命令行如下: 启动SQL Server NET START MSSQLSERVER 暂停SQL Server NET PAUSE MSSQLSERVER 重新启动暂停的SQL Server NET CONTINUE MSSQLSERVER 停止SQL Server NET STOP MSSQLSERVER
评论前必须登录!
注册