MSSQL Broker

MSSQL Broker

Simple one, and this is mainly just for my reference, when restoring a Database in MSSQL, the database will likely keep it's Broker ID. If you're just restoring, then that should be fine, but if you're duplicating a Database, then you will need to give the broker a new identity.

ALTER DATABASE [DatabaseName] SET ENABLE_BROKER

ALTER DATABASE [DatabaseName] SET DISABLE_BROKER

ALTER DATABASE [DatabaseName] SET NEW_BROKER

3 Simple queries to streamline this process. It's so easy, you might not even need one of the queries. Replace mydb with the name of your new database and start with NEW_BROKER, then you can ENABLE_BROKER it.

UPDATE:

I found that it can be hard sometimes to set these options when there are active connections, so a better way to perform the operation would be using the following:

USE master;
GO

-- Set the database to SINGLE_USER mode and disconnect all users
ALTER DATABASE [DatabaseName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO

-- Enable the Service Broker
ALTER DATABASE [DatabaseName] SET ENABLE_BROKER;
GO

-- Set the database back to MULTI_USER mode
ALTER DATABASE [DatabaseName] SET MULTI_USER;
GO
Enabling broker after Restoring Sql Server DataBase
I have DataBase with enabled Service Broker. Then I want to restore my database in program from backup of other database, but after restoring(I restore on existing database name), my method, whitch