Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ namespace TableDependency.SqlClient.Exceptions
public class ServiceBrokerNotEnabledException : TableDependencyException
{
protected internal ServiceBrokerNotEnabledException()
: base("Service broker not enable. Please activete it using 'ALTER DATABASE MyDatabase SET ENABLE_BROKER' command.")
: this("MyDatabase")
{ }

protected internal ServiceBrokerNotEnabledException(string database)
: base($"Service broker is not enabled. Please activate it using 'ALTER DATABASE {database} SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE' command.")
{ }
}
}
18 changes: 17 additions & 1 deletion TableDependency.SqlClient/SqlTableDependency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,23 @@ protected virtual void CheckIfServiceBrokerIsEnabled()
using (var sqlCommand = sqlConnection.CreateCommand())
{
sqlCommand.CommandText = "SELECT is_broker_enabled FROM sys.databases WITH (NOLOCK) WHERE database_id = db_id();";
if ((bool)sqlCommand.ExecuteScalar() == false) throw new ServiceBrokerNotEnabledException();
if ((bool)sqlCommand.ExecuteScalar() == false)
{
string database;
try
{
database = new SqlConnectionStringBuilder(_connectionString).InitialCatalog;
}
catch
{
database = null;
}
if (!string.IsNullOrEmpty(database))
{
throw new ServiceBrokerNotEnabledException(database);
}
throw new ServiceBrokerNotEnabledException();
}
}
}
}
Expand Down