本文可協助您解決在不同實例之間移動 MSDB 資料庫時所發生的許可權問題。
原始產品版本: Microsoft SQL Server
原始 KB 編號: 2000274
徵兆
請參考下列案例:
您可以使用備份和還原程式,或透過資料庫檔案 (mdf 和 ldf) 複製,將 msdb 資料庫從一個實例移至另一個實例。 然後,在目的地伺服器上,不屬於 SQL Server 中 Sysadmin 固定角色的用戶會嘗試執行下列其中一項作業:
- 在 SQL Server Management Studio 中檢視作業。
- 使用 T-SQL 直接呼叫 SQL 代理程式相關的預存程式(例如xp_sqlagent_enum_jobs或sp_get_composite_job_info)。
在此案例中,使用者會收到類似下列的錯誤訊息:
執行 Transact-SQL 陳述式或批次時發生例外狀況。 (Microsoft.SqlServer.ConnectionInfo)
物件 'xp_sqlagent_enum_jobs'、資料庫 'mssqlsystemresource'、架構 'sys' 上的 EXECUTE 許可權遭到拒絕。 (Microsoft SQL Server,錯誤: 229)
原因
發生此問題的原因是 SQL Agent 憑證在不同實例上不同。
解決方法
若要解決此問題,您必須使用目的地伺服器上的下列腳本,將 master 中的憑證取代為已還原 msdb 資料庫的憑證:
use msdb
go
-- Backup the Agent certificate from the remote server to a file
BACKUP CERTIFICATE [##MS_AgentSigningCertificate##] TO FILE = 'MS_AgentSigningCertificate.remote_server.cer'
go
use master
go
-- re-create the agent certificate on master
-- Note: Because we are making these changes using a regular user and not as part of setup, the name
-- cannot include the ## token.
-- Creating a regular certificate in this case should be the equivalent as we only need it to derive a SID
CREATE CERTIFICATE [MS_AgentSigningCertificate.remote_server] FROM FILE = 'MS_AgentSigningCertificate.remote_server.cer'
go
-- Recreate the user mapped to the cert and grant the same permissions that the regular certificate needs.
CREATE USER [MS_AgentSigningCertificate.remote_server] FROM CERTIFICATE [MS_AgentSigningCertificate.remote_server]
go
GRANT EXECUTE TO [MS_AgentSigningCertificate.remote_server]
go
注意
在 master 和 model 中的憑證在執行本文中所討論的腳本之前相同的情況,執行腳本會產生下列錯誤訊息:
訊息 15232,層級 16,狀態 1,第 7 行
名稱為 『MS_AgentSigningCertificate.remote_server20009』 的憑證已經存在,或此憑證已新增至資料庫。
如果您遇到文章中所討論的徵兆,即使憑證相同,請連絡 Microsoft 客戶支援服務 (CSS) 以取得更多協助。