Enable SQL Server 2005 Service Broker

Here's a code tidbit to enable the service broker in SQL Server 2005.  This needs to be running for caching to work in ASP.NET.

IF (SELECT is_broker_enabled
  FROM sys.databases
  WHERE database_id = DB_ID()) = 0
    ALTER DATABASE yourdatabasenamehere
    SET ENABLE_BROKER
    WITH ROLLBACK IMMEDIATE

The if statement checks to see if the broker is already running.  If it is not then it attempts to enable it.  The WITH statement will rollback any other pending transactions that may be blocking this transactions.  This is important because if you run this statement without WITH ROLLBACK IMMEDIATE then it may seem that the batch will not complete.  Again, this is because other transactions or services like SQL Server Agent may be blocking.

About

[Insert Witty Saying Here]