The SQL Server Service Broker for the Current Database is not Enabled, and as a Result Query Notifications are not Supported. Please Enable the Service Broker for this Database if You Wish to Use Not

In my project i was trying to use SqlDependency using this code.

void Application_Start(object sender, EventArgs e)

{

    // Code that runs on application startup

    // Register the default hubs route: ~/signalr

    RouteTable.Routes.MapHubs();         System.Data.SqlClient.SqlDependency.Start(ConfigurationManager.ConnectionStrings["MindcrackerCMSConnectionString"].ConnectionString);

}

So I get this error message.

"The SQL Server Service Broker for the current database is not enabled, and as a result query notifications are not supported.  Please enable the Service Broker for this database if you wish to use not"

Solution

Start SQL Server and write this query to enable broker.

ALTER DATABASE MindcrackerCMS SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE

 
To check weather broker is enable or not run this query.

SELECT is_broker_enabled FROM sys.databases WHERE name = 'MindcrackerCMS'

To kill all the database running process, write this query.

USE master

go

DECLARE @dbname sysname

SET @dbname = 'MindcrackerCMS'

DECLARE @spid int

SELECT @spid = min(spid) from master.dbo.sysprocesses where dbid = db_id(@dbname)

WHILE @spid IS NOT NULL

BEGIN

EXECUTE ('KILL ' + @spid)

SELECT @spid = min(spid) from master.dbo.sysprocesses where dbid = db_id(@dbname) AND spid > @spid

END

ALTER DATABASE @dbname SET ENABLE_BROKER

Note - MindcrackerCMS is my database name.