views:

539

answers:

2

I have made a small ASP.NET website. It uses sqlcachedependency

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 notifications.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: 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 notifications.

Source Error:

Line 12: System.Data.SqlClient.SqlDependency.Start(connString);

This is the erroneous line in my global.asax.

However, in sql server (2005), I enabled service broker like so (I connect and run the SQL Server service when I debug my site):

ALTER DATABASE mynewdatabase SET ENABLE_BROKER with rollback immediate

And this was successful.

What am I missing? I am trying to use sql caching dependency and have followed all procedures.

Thanks

A: 

Do you use a normal SQL instance, including Express, or are you using User Instances? ie. your connection string uses "AttachDbFilename" option? On user instances because the MDF is attached each time the instance is created, the Service Broker gets disabled each time because attach and restore operations always disable the broker in the database.

Remus Rusanu
Normal instance (enterprise edition).
dotnetdev
You can check the `is_broker_enabled` column value in `sys.databases` to confirm that broker is enabled in the database. If is not you need to run ALTER again and perhaps check what component may disable it.
Remus Rusanu
A: 

Ditch the "with rollback immediate" and try running the statement again.

Does it hang? If so kill any other sessions that are in the database and are blocking the session trying to alter the database.

Here's the script I mentioned in my comment.

use master
go
declare @parent int
declare @cmd varchar(100)

set @parent = 53

while exists (select * from sys.sysprocesses where spid = @parent and blocked <> 0)
begin
    select @cmd = 'kill ' + cast(blocked as varchar(10))
    from sys.sysprocesses
    where spid = @parent 

    print @cmd

    exec (@cmd)
end
mrdenny
Yes it does hang without the rollback immediate. I'll try killing the sessions, but I'm the only person logged in/where can I kill sessions?
dotnetdev
Then something else is connected to the database. Close the Object Explorer if needed and any other query windows that you have open. Query the sys.sysprocesses DMV to see what other processes are using the database (or look to see what processes are blocking your ALTER DATABASE command) and use the KILL T/SQL command to kill those processes. You'll need to kill them all to get the ALTER DATABASE command to take effect. I'll post a script I use which should help.
mrdenny