diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs index ee5d088dc4..f546b0436b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs @@ -67,10 +67,11 @@ static LocalAppContextSwitches() #endif /// - /// In TdsParser the ProcessSni function changed significantly when the packet + /// In TdsParser, the ProcessSni function changed significantly when the packet /// multiplexing code needed for high speed multi-packet column values was added. - /// In case of compatibility problems this switch will change TdsParser to use - /// the previous version of the function. + /// When this switch is set to true (the default), the old ProcessSni design is used. + /// When this switch is set to false, the new experimental ProcessSni behavior using + /// the packet multiplexer is enabled. /// public static bool UseCompatibilityProcessSni { @@ -78,7 +79,9 @@ public static bool UseCompatibilityProcessSni { if (s_useCompatibilityProcessSni == Tristate.NotInitialized) { - if (AppContext.TryGetSwitch(UseCompatibilityProcessSniString, out bool returnedValue) && returnedValue) + // Check if the switch has been set by the AppContext switch directly + // If it has not been set, we default to true. + if (!AppContext.TryGetSwitch(UseCompatibilityProcessSniString, out bool returnedValue) || returnedValue) { s_useCompatibilityProcessSni = Tristate.True; } @@ -92,12 +95,12 @@ public static bool UseCompatibilityProcessSni } /// - /// In TdsParser the async multi-packet column value fetch behaviour is capable of - /// using a continue snapshot state in addition to the original replay from start - /// logic. - /// This switch disables use of the continue snapshot state. This switch will always - /// return true if is enabled because the - /// continue state is not stable without the multiplexer. + /// In TdsParser, the async multi-packet column value fetch behavior can use a continue snapshot state + /// for improved efficiency. When this switch is enabled (the default), the driver preserves the legacy + /// compatibility behavior, which does not use the continue snapshot state. When disabled, the new behavior + /// using the continue snapshot state is enabled. This switch will always return true if + /// is enabled, because the continue state is not stable without + /// the multiplexer. /// public static bool UseCompatibilityAsyncBehaviour { @@ -114,7 +117,7 @@ public static bool UseCompatibilityAsyncBehaviour if (s_useCompatibilityAsyncBehaviour == Tristate.NotInitialized) { - if (AppContext.TryGetSwitch(UseCompatibilityAsyncBehaviourString, out bool returnedValue) && returnedValue) + if (!AppContext.TryGetSwitch(UseCompatibilityAsyncBehaviourString, out bool returnedValue) || returnedValue) { s_useCompatibilityAsyncBehaviour = Tristate.True; } diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/MultiplexerTests.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/MultiplexerTests.cs index 288586fb17..efa7962d28 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/MultiplexerTests.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/MultiplexerTests.cs @@ -25,7 +25,7 @@ public static bool IsUsingCompatibilityProcessSni { return foundValue; } - return false; + return true; // Default to true if the switch is not set } } diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs index ec60f0d3cd..c28fe18978 100644 --- a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs @@ -23,8 +23,8 @@ public void TestDefaultAppContextSwitchValues() Assert.False(LocalAppContextSwitches.MakeReadAsyncBlocking); Assert.True(LocalAppContextSwitches.UseMinimumLoginTimeout); Assert.True(LocalAppContextSwitches.LegacyVarTimeZeroScaleBehaviour); - Assert.False(LocalAppContextSwitches.UseCompatibilityProcessSni); - Assert.False(LocalAppContextSwitches.UseCompatibilityAsyncBehaviour); + Assert.True(LocalAppContextSwitches.UseCompatibilityProcessSni); + Assert.True(LocalAppContextSwitches.UseCompatibilityAsyncBehaviour); Assert.False(LocalAppContextSwitches.UseConnectionPoolV2); Assert.False(LocalAppContextSwitches.TruncateScaledDecimal); #if NETFRAMEWORK