Created
November 4, 2012 22:28
-
-
Save duncansmart/4014051 to your computer and use it in GitHub Desktop.
Ensure SQL Service Broker is enabled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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