diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs index bf69c0346d..26fc98f464 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs @@ -762,29 +762,53 @@ internal static Version GetAssemblyVersion() private const string AZURE_SQL_CHINA = ".database.chinacloudapi.cn"; private const string AZURE_SQL_FABRIC = ".database.fabric.microsoft.com"; - internal static bool IsAzureSynapseOnDemandEndpoint(string dataSource) - { - return IsEndpoint(dataSource, ONDEMAND_PREFIX) - || dataSource.Contains(AZURE_SYNAPSE) - || dataSource.Contains(FABRIC_DATAWAREHOUSE) - || dataSource.Contains(PBI_DATAWAREHOUSE) - || dataSource.Contains(PBI_DATAWAREHOUSE2) - || dataSource.Contains(PBI_DATAWAREHOUSE3); - } - + /// + /// Represents a collection of Azure SQL Server endpoint URLs for various regions and environments. + /// + /// This array includes endpoint URLs for Azure SQL in global, Germany, US Government, + /// China, and Fabric environments. These endpoints are used to identify and interact with Azure SQL services + /// in their respective regions or environments. internal static readonly string[] s_azureSqlServerEndpoints = { AZURE_SQL, AZURE_SQL_GERMANY, AZURE_SQL_USGOV, AZURE_SQL_CHINA, AZURE_SQL_FABRIC }; + + /// + /// Contains endpoint strings for Azure SQL Server on-demand services. + /// Each entry is a combination of the ONDEMAND_PREFIX and a specific Azure SQL endpoint string. + /// Example format: "ondemand.database.windows.net". + /// + 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 }; + /// + /// Represents a collection of endpoint identifiers for Azure Synapse and related services. + /// + /// This array contains predefined endpoint strings used to identify Azure Synapse and + /// associated services, such as Fabric Data Warehouse and Power BI Data Warehouse. + internal static readonly string[] s_azureSynapseEndpoints = { FABRIC_DATAWAREHOUSE, + PBI_DATAWAREHOUSE, + PBI_DATAWAREHOUSE2, + PBI_DATAWAREHOUSE3 }; + internal static readonly string[] s_azureSynapseOnDemandEndpoints = [.. s_azureSqlServerOnDemandEndpoints, .. s_azureSynapseEndpoints]; + + internal static bool IsAzureSynapseOnDemandEndpoint(string dataSource) + { + return IsEndpoint(dataSource, s_azureSynapseOnDemandEndpoints) + || dataSource.IndexOf(AZURE_SYNAPSE, StringComparison.OrdinalIgnoreCase) >= 0; + } + 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 @@ -805,8 +829,6 @@ private static bool IsEndpoint(string dataSource, string prefix) foundIndex = -1; } - - if (foundIndex > 0) { length = foundIndex; @@ -819,10 +841,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++) + foreach (var endpoint in endpoints) { - string endpoint = string.IsNullOrEmpty(prefix) ? s_azureSqlServerEndpoints[index] : prefix + s_azureSqlServerEndpoints[index]; - if (length > endpoint.Length) + if (length >= endpoint.Length) { if (string.Compare(dataSource, length - endpoint.Length, endpoint, 0, endpoint.Length, StringComparison.OrdinalIgnoreCase) == 0) { diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionTest.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionTest.cs index d3b906c6b5..d61866f176 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionTest.cs @@ -1100,6 +1100,7 @@ public void ConnectionString_WithOnlyComma() [InlineData("myserver.database.windows.net")] [InlineData("myserver.database.cloudapi.de")] [InlineData("myserver.database.usgovcloudapi.net")] + [InlineData("myserver.DATABASE.usgovcloudapi.net")] [InlineData("myserver.database.chinacloudapi.cn")] [InlineData("myserver.database.fabric.microsoft.com")] public void ConnectionRetryForAzureDbEndpoints(string serverName) @@ -1112,8 +1113,10 @@ public void ConnectionRetryForAzureDbEndpoints(string serverName) [Theory] [InlineData("myserver-ondemand.sql.azuresynapse.net")] + [InlineData("myserver-ondemand.SQL.azuresynapse.net")] [InlineData("someserver-ondemand.database.windows.net")] [InlineData("datawarehouse.fabric.microsoft.com")] + [InlineData("datawarehouse.FABRIC.microsoft.com")] [InlineData("datawarehouse.pbidedicated.microsoft.com")] [InlineData("someserver.pbidedicated.microsoft.com")] [InlineData("someserver.pbidedicated.windows.net")]