Skip to content
Merged
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 @@ -106,6 +106,7 @@ internal SqlConnectionContainer(SqlConnectionContainerHashHelper hashHelper, str
_con.Open();

_cachedServer = _con.DataSource;
bool? dbId = null;

#if NETFRAMEWORK
if (hashHelper.Identity != null)
Expand All @@ -125,7 +126,16 @@ internal SqlConnectionContainer(SqlConnectionContainerHashHelper hashHelper, str
CommandText = "select is_broker_enabled from sys.databases where database_id=db_id()"
};

if (!(bool)_com.ExecuteScalar())
// db_id() returns the database ID of the current database hence it will always be one line result
using (SqlDataReader reader = _com.ExecuteReader(CommandBehavior.SingleRow))
{
if (reader.Read() && reader[0] is not null)
{
dbId = reader.GetBoolean(0);
}
}

if (dbId is null || !dbId.Value)
{
throw SQL.SqlDependencyDatabaseBrokerDisabled();
}
Expand Down