Skip to content

Instantly share code, notes, and snippets.

@duncansmart
Created November 4, 2012 22:28
Show Gist options
  • Save duncansmart/4014051 to your computer and use it in GitHub Desktop.
Save duncansmart/4014051 to your computer and use it in GitHub Desktop.
Ensure SQL Service Broker is enabled
static void ensureServiceBrokerEnabled()
{
var sql = @"if (SELECT is_broker_enabled FROM sys.databases WHERE name = DB_NAME()) = 0
begin
declare @sql nvarchar(max) = 'ALTER DATABASE ' + QUOTENAME(DB_NAME()) + ' SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE'
exec(@sql)
end";
using (var db = DependencyResolver.Current.GetService<IDbConnection>())
{
db.Open();
db.Execute(sql);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment