3
3
// See the LICENSE file in the project root for more information.
4
4
5
5
using System ;
6
- using System . Reflection ;
7
- using System . Runtime . CompilerServices ;
8
6
9
7
namespace Microsoft . Data . SqlClient
10
8
{
@@ -13,10 +11,12 @@ internal static partial class LocalAppContextSwitches
13
11
internal const string MakeReadAsyncBlockingString = @"Switch.Microsoft.Data.SqlClient.MakeReadAsyncBlocking" ;
14
12
internal const string LegacyRowVersionNullString = @"Switch.Microsoft.Data.SqlClient.LegacyRowVersionNullBehavior" ;
15
13
internal const string SuppressInsecureTLSWarningString = @"Switch.Microsoft.Data.SqlClient.SuppressInsecureTLSWarning" ;
14
+ internal const string UseMinimumLoginTimeoutString = @"Switch.Microsoft.Data.SqlClient.UseOneSecFloorInTimeoutCalculationDuringLogin" ;
16
15
16
+ private static bool ? s_legacyRowVersionNullBehavior ;
17
+ private static bool ? s_suppressInsecureTLSWarning ;
17
18
private static bool s_makeReadAsyncBlocking ;
18
- private static bool ? s_LegacyRowVersionNullBehavior ;
19
- private static bool ? s_SuppressInsecureTLSWarning ;
19
+ private static bool s_useMinimumLoginTimeout ;
20
20
21
21
#if ! NETFRAMEWORK
22
22
static LocalAppContextSwitches ( )
@@ -34,46 +34,81 @@ static LocalAppContextSwitches()
34
34
}
35
35
#endif
36
36
37
+ #if NETFRAMEWORK
38
+ internal const string DisableTNIRByDefaultString = @"Switch.Microsoft.Data.SqlClient.DisableTNIRByDefaultInConnectionString" ;
39
+ private static bool s_disableTNIRByDefault ;
40
+
41
+ /// <summary>
42
+ /// Transparent Network IP Resolution (TNIR) is a revision of the existing MultiSubnetFailover feature.
43
+ /// TNIR affects the connection sequence of the driver in the case where the first resolved IP of the hostname
44
+ /// doesn't respond and there are multiple IPs associated with the hostname.
45
+ ///
46
+ /// TNIR interacts with MultiSubnetFailover to provide the following three connection sequences:
47
+ /// 0: One IP is attempted, followed by all IPs in parallel
48
+ /// 1: All IPs are attempted in parallel
49
+ /// 2: All IPs are attempted one after another
50
+ ///
51
+ /// TransparentNetworkIPResolution is enabled by default. MultiSubnetFailover is disabled by default.
52
+ /// To disable TNIR, you can enable the app context switch.
53
+ ///
54
+ /// This app context switch defaults to 'false'.
55
+ /// </summary>
56
+ public static bool DisableTNIRByDefault
57
+ => AppContext . TryGetSwitch ( DisableTNIRByDefaultString , out s_disableTNIRByDefault ) && s_disableTNIRByDefault ;
58
+ #endif
59
+
60
+ /// <summary>
61
+ /// When using Encrypt=false in the connection string, a security warning is output to the console if the TLS version is 1.2 or lower.
62
+ /// This warning can be suppressed by enabling this AppContext switch.
63
+ /// This app context switch defaults to 'false'.
64
+ /// </summary>
37
65
public static bool SuppressInsecureTLSWarning
38
66
{
39
67
get
40
68
{
41
- if ( s_SuppressInsecureTLSWarning is null )
69
+ if ( s_suppressInsecureTLSWarning is null )
42
70
{
43
71
bool result ;
44
- result = AppContext . TryGetSwitch ( SuppressInsecureTLSWarningString , out result ) ? result : false ;
45
- s_SuppressInsecureTLSWarning = result ;
72
+ result = AppContext . TryGetSwitch ( SuppressInsecureTLSWarningString , out result ) && result ;
73
+ s_suppressInsecureTLSWarning = result ;
46
74
}
47
- return s_SuppressInsecureTLSWarning . Value ;
48
- }
49
- }
50
-
51
- public static bool MakeReadAsyncBlocking
52
- {
53
- [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
54
- get
55
- {
56
- return AppContext . TryGetSwitch ( MakeReadAsyncBlockingString , out s_makeReadAsyncBlocking ) ? s_makeReadAsyncBlocking : false ;
75
+ return s_suppressInsecureTLSWarning . Value ;
57
76
}
58
77
}
59
78
60
79
/// <summary>
61
80
/// In System.Data.SqlClient and Microsoft.Data.SqlClient prior to 3.0.0 a field with type Timestamp/RowVersion
62
81
/// would return an empty byte array. This switch contols whether to preserve that behaviour on newer versions
63
- /// of Microsoft.Data.SqlClient, if this switch returns false an appropriate null value will be returned
82
+ /// of Microsoft.Data.SqlClient, if this switch returns false an appropriate null value will be returned.
83
+ /// This app context switch defaults to 'false'.
64
84
/// </summary>
65
85
public static bool LegacyRowVersionNullBehavior
66
86
{
67
87
get
68
88
{
69
- if ( s_LegacyRowVersionNullBehavior is null )
89
+ if ( s_legacyRowVersionNullBehavior is null )
70
90
{
71
91
bool result ;
72
- result = AppContext . TryGetSwitch ( LegacyRowVersionNullString , out result ) ? result : false ;
73
- s_LegacyRowVersionNullBehavior = result ;
92
+ result = AppContext . TryGetSwitch ( LegacyRowVersionNullString , out result ) && result ;
93
+ s_legacyRowVersionNullBehavior = result ;
74
94
}
75
- return s_LegacyRowVersionNullBehavior . Value ;
95
+ return s_legacyRowVersionNullBehavior . Value ;
76
96
}
77
97
}
98
+
99
+ /// <summary>
100
+ /// When enabled, ReadAsync runs asynchronously and does not block the calling thread.
101
+ /// This app context switch defaults to 'false'.
102
+ /// </summary>
103
+ public static bool MakeReadAsyncBlocking
104
+ => AppContext . TryGetSwitch ( MakeReadAsyncBlockingString , out s_makeReadAsyncBlocking ) && s_makeReadAsyncBlocking ;
105
+
106
+ /// <summary>
107
+ /// Specifies minimum login timeout to be set to 1 second instead of 0 seconds,
108
+ /// to prevent a login attempt from waiting indefinitely.
109
+ /// This app context switch defaults to 'true'.
110
+ /// </summary>
111
+ public static bool UseMinimumLoginTimeout
112
+ => ! AppContext . TryGetSwitch ( UseMinimumLoginTimeoutString , out s_useMinimumLoginTimeout ) || s_useMinimumLoginTimeout ;
78
113
}
79
114
}
0 commit comments