How to recover Service Broker after restoring database?

不羁的心 提交于 2021-01-25 01:47:15


After db restoring on other server the Service Broker is stopped. The restored db has a Trustworthy Off and now I set it to On to run Broker again. I understand that it is bad practice. Especially after reading articles by solomon-rutzky. I have made as Solomon advised for SQLCLR UNSAFE functions without setting database to TRUSTWORTHY ON. It works fine!

How to restore Broker working in case TRUSTWORTHY OFF?


Trustworthy isn't required to run Service Broker. There is, however, an option that you can pass to the RESTORE statement that is probably what you need. Quoting the docs:


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.

If you didn't do this, there is still hope! Post-restore, you can issue an alter databse [yourDB] set enable_broker;. Note, this requires exclusive database access, so you might also need to add with rollback immediate or similar to the alter database statement.