主数据库中记录的数据库所有者SID与数据库所有者SID不同 [英] The database owner SID recorded in the master database differs from the database owner SID

查看:518
本文介绍了主数据库中记录的数据库所有者SID与数据库所有者SID不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试将tSQLt安装到现有数据库上时,出现以下错误:

When I try to install tSQLt onto an existing database i get the following error:

主数据库中记录的数据库所有者SID与 记录在数据库"中的数据库所有者SID.你应该纠正 通过使用ALTER重置数据库所有者来解决这种情况 授权声明.

The database owner SID recorded in the master database differs from the database owner SID recorded in database ''. You should correct this situation by resetting the owner of database '' using the ALTER AUTHORIZATION statement.

推荐答案

当从备份还原的数据库且数据库所有者的SID与主数据库中列出的所有者SID不匹配时,可能会出现此问题.这是使用错误消息中建议的"ALTER AUTHORIZATION"语句的解决方案:

This problem can arise when a database restored from a backup and the SID of the database owner does not match the owners SID listed in the master database. Here is a solution that uses the "ALTER AUTHORIZATION" statement recommended in the error message:

DECLARE @Command VARCHAR(MAX) = 'ALTER AUTHORIZATION ON DATABASE::[<<DatabaseName>>] TO 
[<<LoginName>>]' 

SELECT @Command = REPLACE(REPLACE(@Command 
            , '<<DatabaseName>>', SD.Name)
            , '<<LoginName>>', SL.Name)
FROM master..sysdatabases SD 
JOIN master..syslogins SL ON  SD.SID = SL.SID
WHERE  SD.Name = DB_NAME()

PRINT @Command
EXEC(@Command)

这篇关于主数据库中记录的数据库所有者SID与数据库所有者SID不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆