Skip to content

avoid some allocations when opening a connection #3364

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

Merged
merged 4 commits into from
May 26, 2025
Merged
Changes from 1 commit
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 @@ -764,7 +764,7 @@ internal static Version GetAssemblyVersion()

internal static bool IsAzureSynapseOnDemandEndpoint(string dataSource)
{
return IsEndpoint(dataSource, ONDEMAND_PREFIX)
return IsEndpoint(dataSource, s_azureSqlServerOnDemandEndpoints)
|| dataSource.Contains(AZURE_SYNAPSE)
|| dataSource.Contains(FABRIC_DATAWAREHOUSE)
|| dataSource.Contains(PBI_DATAWAREHOUSE)
Expand All @@ -777,14 +777,20 @@ internal static bool IsAzureSynapseOnDemandEndpoint(string dataSource)
AZURE_SQL_USGOV,
AZURE_SQL_CHINA,
AZURE_SQL_FABRIC };

internal static readonly string[] s_azureSqlServerOnDemandEndpoints = { ONDEMAND_PREFIX + AZURE_SQL,
ONDEMAND_PREFIX + AZURE_SQL_GERMANY,
ONDEMAND_PREFIX + AZURE_SQL_USGOV,
ONDEMAND_PREFIX + AZURE_SQL_CHINA,
ONDEMAND_PREFIX + AZURE_SQL_FABRIC };

internal static bool IsAzureSqlServerEndpoint(string dataSource)
{
return IsEndpoint(dataSource, null);
return IsEndpoint(dataSource, s_azureSqlServerEndpoints);
}

// This method assumes dataSource parameter is in TCP connection string format.
private static bool IsEndpoint(string dataSource, string prefix)
private static bool IsEndpoint(string dataSource, string[] endpoints)
{
int length = dataSource.Length;
// remove server port
Expand All @@ -805,8 +811,6 @@ private static bool IsEndpoint(string dataSource, string prefix)
foundIndex = -1;
}



if (foundIndex > 0)
{
length = foundIndex;
Expand All @@ -819,9 +823,9 @@ private static bool IsEndpoint(string dataSource, string prefix)
}

// check if servername ends with any endpoints
for (int index = 0; index < s_azureSqlServerEndpoints.Length; index++)
for (int index = 0; index < endpoints.Length; index++)
{
string endpoint = string.IsNullOrEmpty(prefix) ? s_azureSqlServerEndpoints[index] : prefix + s_azureSqlServerEndpoints[index];
string endpoint = endpoints[index];
if (length > endpoint.Length)
{
if (string.Compare(dataSource, length - endpoint.Length, endpoint, 0, endpoint.Length, StringComparison.OrdinalIgnoreCase) == 0)
Expand Down