恢复数据库后如何恢复Service Broker?

How to recover Service Broker after restoring database?

在其他服务器上恢复数据库后,Service Broker 停止。 恢复的数据库有一个 Trustworthy Off,现在我再次将它设置为 On 运行 Broker。 我知道这是不好的做法。尤其是在阅读了 solomon-rutzky 的文章之后。 我已经按照 Solomon 的建议为 SQLCLR UNSAFE 函数做了,而没有将数据库设置为 TRUSTWORTHY ON。效果很好!

如何在 TRUSTWORTHY OFF 的情况下恢复 Broker 的工作?

运行 Service Broker 不需要可信赖。但是,您可以将一个选项传递给 RESTORE 语句,这可能正是您所需要的。引用 the docs:

ENABLE_BROKER

Specifies that Service Broker message delivery is enabled at the end of the restore so that messages can be sent immediately. By default Service Broker message delivery is disabled during a restore. The database retains the existing Service Broker identifier.

如果你不这样做,还有希望! Post-恢复,你可以发出一个alter databse [yourDB] set enable_broker;。请注意,这需要独占数据库访问权限,因此您可能还需要添加 with rollback immediate 或类似于 alter database 语句。