From 1ceeacbcdb13a61ee9bc1e93f04824cea5517c31 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Wed, 17 Apr 2024 13:13:07 -0500 Subject: [PATCH 1/2] Adding TransparentNetworkIpResolution to list of unsupported on platform connection string error messages Splitting unit test for netfx-only connection string properties such that test does not fail on netcore --- .../Data/Common/DbConnectionStringCommon.cs | 5 ++- .../SqlClient/SqlConnectionStringBuilder.cs | 9 ++--- .../SqlConnectionStringBuilderTest.cs | 33 ++++++++++++++----- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/DbConnectionStringCommon.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/DbConnectionStringCommon.cs index 35aaf412a5..95a54538f9 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/DbConnectionStringCommon.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/DbConnectionStringCommon.cs @@ -1037,7 +1037,6 @@ internal static class DbConnectionStringKeywords internal const string OmitOracleConnectionName = "Omit Oracle Connection Name"; // SqlClient - internal const string TransparentNetworkIPResolution = "Transparent Network IP Resolution"; internal const string Certificate = "Certificate"; #endif // SqlClient @@ -1073,6 +1072,7 @@ internal static class DbConnectionStringKeywords internal const string IPAddressPreference = "IP Address Preference"; internal const string ServerSPN = "Server SPN"; internal const string FailoverPartnerSPN = "Failover Partner SPN"; + internal const string TransparentNetworkIPResolution = "Transparent Network IP Resolution"; // common keywords (OleDb, OracleClient, SqlClient) internal const string DataSource = "Data Source"; @@ -1092,10 +1092,9 @@ internal static class DbConnectionStringKeywords internal static class DbConnectionStringSynonyms { -#if NETFRAMEWORK //internal const string TransparentNetworkIPResolution = TRANSPARENTNETWORKIPRESOLUTION; internal const string TRANSPARENTNETWORKIPRESOLUTION = "transparentnetworkipresolution"; -#endif + //internal const string ApplicationName = APP; internal const string APP = "app"; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionStringBuilder.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionStringBuilder.cs index c9f9fd2912..72f87403c8 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionStringBuilder.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionStringBuilder.cs @@ -363,7 +363,6 @@ private object GetAt(Keywords index) return MinPoolSize; case Keywords.MultiSubnetFailover: return MultiSubnetFailover; - // case Keywords.NamedConnection: return NamedConnection; case Keywords.PacketSize: return PacketSize; case Keywords.Password: @@ -912,17 +911,19 @@ public override StandardValuesCollection GetStandardValues(ITypeDescriptorContex } } #else - private static readonly string[] s_notSupportedKeywords = new string[DeprecatedKeywordsCount] { + private static readonly string[] s_notSupportedKeywords = { DbConnectionStringKeywords.ConnectionReset, DbConnectionStringKeywords.ContextConnection, DbConnectionStringKeywords.TransactionBinding, + DbConnectionStringKeywords.TransparentNetworkIPResolution, + DbConnectionStringSynonyms.TRANSPARENTNETWORKIPRESOLUTION, }; - private static readonly string[] s_notSupportedNetworkLibraryKeywords = new string[] { + private static readonly string[] s_notSupportedNetworkLibraryKeywords = { DbConnectionStringKeywords.NetworkLibrary, DbConnectionStringSynonyms.NET, - DbConnectionStringSynonyms.NETWORK + DbConnectionStringSynonyms.NETWORK, }; #endif #endregion //Private Methods diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionStringBuilderTest.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionStringBuilderTest.cs index d1c3fd2d34..05b3ca5b48 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionStringBuilderTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionStringBuilderTest.cs @@ -107,19 +107,34 @@ public void ConnectionStringTests(string connectionString) ExecuteConnectionStringTests(connectionString); } + public static readonly IEnumerable ConnectionStringTestsNetFx_TestCases = new[] + { + new object[] { "Connection Reset = false" }, + new object[] { "Context Connection = false" }, + new object[] { "Network Library = dbmssocn" }, + new object[] { "Network = dbnmpntw" }, + new object[] { "Net = dbmsrpcn" }, + new object[] { "TransparentNetworkIPResolution = false" }, + new object[] { "Transparent Network IP Resolution = true" }, + }; + [Theory] - [InlineData("Connection Reset = false")] - [InlineData("Context Connection = false")] - [InlineData("Network Library = dbmssocn")] - [InlineData("Network = dbnmpntw")] - [InlineData("Net = dbmsrpcn")] - [InlineData("TransparentNetworkIPResolution = false")] - [InlineData("Transparent Network IP Resolution = true")] - [SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)] - public void ConnectionStringTestsNetFx(string connectionString) + [MemberData(nameof(ConnectionStringTestsNetFx_TestCases))] + #if NETFRAMEWORK + public void ConnectionStringTestsNetFx_OnNetFx_Success(string connectionString) { ExecuteConnectionStringTests(connectionString); } + #else + public void ConnectionStringTestsNetFx_OnNetCore_Throws(string connectionString) + { + // Act + Action action = () => _ = new SqlConnectionStringBuilder(connectionString); + + // Assert + Assert.Throws(action); + } + #endif [Fact] public void SetInvalidApplicationIntent_Throws() From 807856023ee63daf5245cff53691293fa2be0304 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Wed, 24 Apr 2024 12:08:53 -0500 Subject: [PATCH 2/2] Remove DeprecatedSynonymCount since referencing the unsupported array is not possible --- .../src/Microsoft/Data/SqlClient/SqlConnectionString.cs | 3 +-- .../src/Microsoft/Data/SqlClient/SqlConnectionStringBuilder.cs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionString.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionString.cs index 690a4e810a..1e9dc8a031 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionString.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionString.cs @@ -233,7 +233,6 @@ internal static class TRANSACTIONBINDING internal const int SynonymCount = 33; #else internal const int SynonymCount = 30; - internal const int DeprecatedSynonymCount = 2; #endif // NETFRAMEWORK private static Dictionary s_sqlClientSynonyms; @@ -837,7 +836,7 @@ internal static Dictionary GetParseSynonyms() int count = SqlConnectionStringBuilder.KeywordsCount + SynonymCount; #if !NETFRAMEWORK - count += SqlConnectionStringBuilder.DeprecatedKeywordsCount + DeprecatedSynonymCount; + count += SqlConnectionStringBuilder.DeprecatedKeywordsCount; #endif synonyms = new Dictionary(count, StringComparer.OrdinalIgnoreCase) { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionStringBuilder.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionStringBuilder.cs index 72f87403c8..60e3950d0b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionStringBuilder.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionStringBuilder.cs @@ -139,7 +139,7 @@ private enum Keywords private string _certificate = DbConnectionStringDefaults.Certificate; #endif #else - internal const int DeprecatedKeywordsCount = 3; + internal const int DeprecatedKeywordsCount = 5; #endif #endregion //Fields