Enabling and Resetting Service Broker

The SET ENABLE_BROKER statement is used in SQL Server to enable the Service Broker in a database. Service Broker is a feature for building asynchronous, message-based applications within the SQL Server database engine. When you enable Service Broker, it allows the database to send and receive messages, which can be useful for various tasks such as queuing, workflow, and integration with other systems.

To enable Service Broker in a user database, you need to make sure no other sessions are using the database before you run the ALTER DATABASE SET ENABLE_BROKER statement. This might involve putting the database in single-user mode to avoid conflicts

Here is an example of how you might use this statement:

USE master;
GO
ALTER DATABASE [YourDatabaseName] SET ENABLE_BROKER;
GO

--------

select database_id,queue_id,[state] from sys.dm_broker_queue_monitors m
 WHERE state='DROPPED'
   and not exists (select 1 from sys.dm_broker_queue_monitors m2
                    where state <> 'DROPPED'
                          and m.queue_id=m2.queue_id
                          and m.database_id=m2.database_id)
--------

ALTER DATABASE [dbname] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE [dbname] SET ENABLE_BROKER WITH NO_WAIT
ALTER DATABASE [dbname] SET MULTI_USER

ALTER DATABASE [dbname] SET NEW_BROKER WITH ROLLBACK IMMEDIATE
--SELECT * FROM sysdatabases
--SELECT * FROM sys.dm_broker_queue_monitors

--SET NEW_BROKER NOT [YourDatabaseName]
ALTER DATABASE [YourDatabaseName] SET NEW_BROKER WITH ROLLBACK IMMEDIATE;
--to restart the broker

From my SQL Server DBA handbook.