执行更新数据库脚本时 SQL Server 升级失败,错误代码为 2714

本文解决了运行数据库升级脚本时累积更新(CU)或 Service Pack(SP)报告错误 2714 的问题。

现象

应用 CU 或 SP 时,安装程序可能会报告以下错误:

等待数据库引擎恢复句柄失败。 有关可能的原因,请查看 SQL Server 错误日志。

查看 SQL Server 错误日志时,可能会注意到以下错误消息之一:

2021-07-27 14:08:44.31 spid6s      Error: 2714, Severity: 16, State: 6.
2021-07-27 14:08:44.31 spid6s      There is already an object named 'DatabaseMailUserRole' in the database.
2021-07-27 14:08:44.31 spid6s      Error: 2759, Severity: 16, State: 0.
2021-07-27 14:08:44.31 spid6s      CREATE SCHEMA failed due to previous errors.
2021-07-27 14:08:44.31 spid6s      Error: 912, Severity: 21, State: 2.
2021-07-27 14:08:44.31 spid6s      Script level upgrade for database 'master' failed because upgrade step 'msdb110_upgrade.sql' encountered error 2714, state 6, severity 25.
This is a serious error condition which might interfere with regular operation and the database will be taken offline.
If the error happened during upgrade of the 'master' database, it will prevent the entire SQL Server instance from starting.
Examine the previous errorlog entries for errors, take the appropriate corrective actions and re-start the database so that the script upgrade steps run to completion.
2021-07-27 14:08:44.32 spid6s      Error: 3417, Severity: 21, State: 3.
Restore master from a full backup, repair it, or rebuild it. For more information about how to rebuild the master database, see SQL Server Books Online.
2021-07-27 14:08:44.31 spid6s      Error: 2714, Severity: 16, State: 6.
2021-07-27 14:08:44.31 spid6s      There is already an object named 'TargetServersRole' in the database.
2021-07-27 14:08:44.31 spid6s      Error: 912, Severity: 21, State: 2.
2021-07-27 14:08:44.31 spid6s      Script level upgrade for database 'master' failed because upgrade step 'msdb110_upgrade.sql' encountered error 2714, state 6, severity 25.
This is a serious error condition which might interfere with regular operation and the database will be taken offline.
If the error happened during upgrade of the 'master' database, it will prevent the entire SQL Server instance from starting.
Examine the previous errorlog entries for errors, take the appropriate corrective actions and re-start the database so that the script upgrade steps run to completion.
2021-07-27 14:08:44.32 spid6s      Error: 3417, Severity: 21, State: 3.
Restore master from a full backup, repair it, or rebuild it. For more information about how to rebuild the master database, see SQL Server Books Online.

解决 DatabaseMailUserRole 架构的升级问题

查看以下信息以解决与 <a0/&a0> 关联的升级问题。

原因

如果在数据库中配置 msdb 了系统架构、用户或角色,则会发生此错误。

升级脚本在数据库中无法重新创建 DatabaseMailUserRole 架构 msdb 时也会发生这种情况。 当架构不由DatabaseMailUserRole角色拥有时DatabaseMailUserRole,可能会出现此问题;例如,如果架构由该dbo架构拥有。

有关在 CU 或 SP 安装过程中执行的数据库升级脚本的详细信息,请参阅 应用更新时对升级脚本失败进行故障排除。

解决方法

  1. 使用 T902 停止和重启 SQL Server。 例如,可以从命令提示符运行以下命令:

    对于默认实例:

    NET START MSSQLSERVER /T902
    

    对于命名实例:

    NET START MSSQL$INSTANCENAME  /T902
    
  2. 备份 msdb 数据库作为预防措施。

    BACKUP DATABASE msdb TO disk = '<backup folder>'
    
  3. 打开 SQL Server Management Studio,连接到 SQL Server 实例并备份 msdb 数据库。

  4. 展开数据库>系统数据库>msdb>安全>架构>DatabaseMailuserRole。

  5. 删除名为 DatabaseMailUserRole..

  6. 停止 SQL Server,并在没有跟踪标志 902 的情况下重新启动它。

    SQL Server 启动且没有跟踪标志 902 后,将再次执行升级脚本,并 DatabaseMailUserRole 重新创建架构。

    • 如果 SP 或 CU 升级脚本成功完成,请检查 SQL Server 错误日志和启动文件夹以验证。
    • 如果升级脚本再次失败,请检查 SQL Server 错误日志中是否存在其他错误,并排查新错误。

解决 TargetServersRole 角色的升级问题

查看以下信息以解决与 <a0/&a0> 关联的升级问题。

原因

升级脚本无法在数据库中重新创建 TargetServersRole 安全角色 msdb 时发生此错误。 此角色用于多服务器环境。 默认情况下, TargetServersRole 安全角色由该 dbo角色拥有,该角色拥有 TargetServersRole 架构。 如果无意中更改此关联,而所安装的更新包括对这些角色之一的更改,升级可能会失败并返回错误 2714: There is already an object named 'TargetServersRole' in the database。 若要解决该错误,请执行以下步骤:

解决方法

  1. 使用 T902 停止和重启 SQL Server。

    对于默认实例:

    NET START MSSQLSERVER /T902
    

    对于命名实例:

    NET START MSSQL$INSTANCENAME /T902
    
  2. 备份 msdb 数据库作为预防措施。

    BACKUP DATABASE msdb TO disk = '<backup folder>'
    
  3. 列出当前属于此角色的用户(如果有)。 可以通过运行以下查询列出角色的成员:

    EXEC msdb.dbo.sp_helprolemember 'TargetServersRole'
    
  4. TargetServersRole使用以下语句删除角色:

    EXEC msdb.dbo.sp_droprole @rolename = N'TargetServersRole'
    
  5. 若要检查问题是否已解决,请在不使用跟踪标志 902的情况下重启 SQL Server 实例。

  6. 将步骤 3 中的 TargetServersRole用户重新添加到 。