Restoring database with Service Broker on same database server Instance

Restoring database from database situated on same SQL server instance with Service Broker enabled can lead to some issues.

When enabling restored database you can get error message The Service Broker in database “DB_Test” cannot be enabled because there is already an enabled Service Broker with the same ID.

There cannot be two Service Brokers enabled with the same GUID identificator. You can check it with query:


SELECT   [name]
 ,[is_broker_enabled]
 ,[service_broker_guid]
FROM [sys].[databases]
List service broker GUIDS
List service broker GUIDS

Use command bellow to generate new Service Broker GUID to be able to enable it.

USE [master] 
GO
ALTER DATABASE [DB_Test]
SET NEW_BROKER
GO

If script above would not finish in expected time (few seconds), modify it little bit to script mentioned bellow.

USE [master] 
GO
ALTER DATABASE [DB_Test]
SET NEW_BROKER WITH ROLLBACK IMMEDIATE
GO

In next posts I will describe another issues you can meet when getting Service Broker on.