Enable SQL Broker after Database Restore

3.2k Views Asked by At

I've restored SQL server database where it enabled SQL Broker Services. Now in Restored Database I need to re-enable these service in SQL Broker, after some online research I came to know that executing one or more query listed below might helps,

ALTER DATABASE [dbname] SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE;
ALTER DATABASE [dbname] SET DISABLE_BROKER WITH ROLLBACK IMMEDIATE;
ALTER DATABASE [dbname] SET NEW_BROKER WITH ROLLBACK IMMEDIATE;

Now in what order I need to execute these Queries, I have two questions :

  1. What will be the first query I need to execute
  2. What will be the last query I required to execute?
1

There are 1 best solutions below

1
On BEST ANSWER

I'd do none of the above. Specifically, if I was trying to ensure that Service Broker was enabled after a restore, I'd specify that in the restore command. Either of:

restore database [yourDatabase] with recovery, enable_broker;
restore database [yourDatabase] with recovery, new_broker;

What informs the choice of which to use? If you want the restored database to maintain the same Service Broker identifier (GUID) after restore and keep any in-flight messages that were present when the backup was taken, use the first. If you want it to generate a new GUID and clear the in-flight messages, use the second.