Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX | db_id returns null on Azure SQL Database. #1294

Merged
merged 5 commits into from
May 27, 2022
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