Search code examples
sql-serversqlclrservice-broker

How to recover Service Broker after restoring database?


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?


Solution

  • 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:

    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.

    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.