@@ -11,49 +11,73 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests.SystemDataInternals
1111 internal static class ConnectionHelper
1212 {
1313 private static Assembly s_MicrosoftDotData = Assembly . Load ( new AssemblyName ( typeof ( SqlConnection ) . GetTypeInfo ( ) . Assembly . FullName ) ) ;
14- private static Type s_sqlConnection = s_MicrosoftDotData . GetType ( "Microsoft.Data.SqlClient.SqlConnection" ) ;
15- private static Type s_sqlInternalConnection = s_MicrosoftDotData . GetType ( "Microsoft.Data.SqlClient.SqlInternalConnection" ) ;
16- private static Type s_sqlInternalConnectionTds = s_MicrosoftDotData . GetType ( "Microsoft.Data.SqlClient.SqlInternalConnectionTds" ) ;
17- private static Type s_dbConnectionInternal = s_MicrosoftDotData . GetType ( "Microsoft.Data.ProviderBase.DbConnectionInternal" ) ;
18- private static Type s_tdsParser = s_MicrosoftDotData . GetType ( "Microsoft.Data.SqlClient.TdsParser" ) ;
19- private static Type s_tdsParserStateObject = s_MicrosoftDotData . GetType ( "Microsoft.Data.SqlClient.TdsParserStateObject" ) ;
20- private static Type s_SQLDNSInfo = s_MicrosoftDotData . GetType ( "Microsoft.Data.SqlClient.SQLDNSInfo" ) ;
21- private static PropertyInfo s_sqlConnectionInternalConnection = s_sqlConnection . GetProperty ( "InnerConnection" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
22- private static PropertyInfo s_dbConnectionInternalPool = s_dbConnectionInternal . GetProperty ( "Pool" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
23- private static MethodInfo s_dbConnectionInternalIsConnectionAlive = s_dbConnectionInternal . GetMethod ( "IsConnectionAlive" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
24- private static FieldInfo s_sqlInternalConnectionTdsParser = s_sqlInternalConnectionTds . GetField ( "_parser" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
25- private static PropertyInfo s_innerConnectionProperty = s_sqlConnection . GetProperty ( "InnerConnection" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
26- private static PropertyInfo s_tdsParserProperty = s_sqlInternalConnectionTds . GetProperty ( "Parser" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
27- private static FieldInfo s_tdsParserStateObjectProperty = s_tdsParser . GetField ( "_physicalStateObj" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
28- private static FieldInfo s_enforceTimeoutDelayProperty = s_tdsParserStateObject . GetField ( "_enforceTimeoutDelay" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
29- private static FieldInfo s_enforcedTimeoutDelayInMilliSeconds = s_tdsParserStateObject . GetField ( "_enforcedTimeoutDelayInMilliSeconds" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
30- private static FieldInfo s_pendingSQLDNSObject = s_sqlInternalConnectionTds . GetField ( "pendingSQLDNSObject" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
31- private static PropertyInfo s_pendingSQLDNS_FQDN = s_SQLDNSInfo . GetProperty ( "FQDN" , BindingFlags . Instance | BindingFlags . Public ) ;
32- private static PropertyInfo s_pendingSQLDNS_AddrIPv4 = s_SQLDNSInfo . GetProperty ( "AddrIPv4" , BindingFlags . Instance | BindingFlags . Public ) ;
33- private static PropertyInfo s_pendingSQLDNS_AddrIPv6 = s_SQLDNSInfo . GetProperty ( "AddrIPv6" , BindingFlags . Instance | BindingFlags . Public ) ;
34- private static PropertyInfo s_pendingSQLDNS_Port = s_SQLDNSInfo . GetProperty ( "Port" , BindingFlags . Instance | BindingFlags . Public ) ;
35- private static PropertyInfo dbConnectionInternalIsTransRoot = s_dbConnectionInternal . GetProperty ( "IsTransactionRoot" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
36- private static PropertyInfo dbConnectionInternalEnlistedTrans = s_sqlInternalConnection . GetProperty ( "EnlistedTransaction" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
37- private static PropertyInfo dbConnectionInternalIsTxRootWaitingForTxEnd = s_dbConnectionInternal . GetProperty ( "IsTxRootWaitingForTxEnd" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
14+
15+ // DbConnectionInternal
16+ private static readonly Type s_dbConnectionInternal = s_MicrosoftDotData . GetType ( "Microsoft.Data.ProviderBase.DbConnectionInternal" ) ;
17+ private static readonly MethodInfo s_dbConnectionInternal_IsConnectionAlive =
18+ s_dbConnectionInternal . GetMethod ( "IsConnectionAlive" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
19+ private static readonly PropertyInfo s_dbConnectionInternal_IsTransationRoot =
20+ s_dbConnectionInternal . GetProperty ( "IsTransactionRoot" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
21+ private static readonly PropertyInfo s_dbConnectionInternal_IsTxRootWaitingForTxEnd =
22+ s_dbConnectionInternal . GetProperty ( "IsTxRootWaitingForTxEnd" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
23+ private static readonly PropertyInfo s_dbConnectionInternal_Pool =
24+ s_dbConnectionInternal . GetProperty ( "Pool" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
25+
26+ // SqlConnection
27+ private static readonly Type s_sqlConnection = s_MicrosoftDotData . GetType ( "Microsoft.Data.SqlClient.SqlConnection" ) ;
28+ private static readonly PropertyInfo s_sqlConnection_InnerConnection =
29+ s_sqlConnection . GetProperty ( "InnerConnection" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
30+
31+ // SqlConnectionInternal
32+ private static readonly Type s_sqlConnectionInternal = s_MicrosoftDotData . GetType ( "Microsoft.Data.SqlClient.Connection.SqlConnectionInternal" ) ;
33+ private static readonly PropertyInfo s_sqlConnectionInternal_EnlistedTransaction =
34+ s_sqlConnectionInternal . GetProperty ( "EnlistedTransaction" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
35+ private static readonly PropertyInfo s_sqlConnectionInternal_Parser =
36+ s_sqlConnectionInternal . GetProperty ( "Parser" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
37+ private static readonly FieldInfo s_sqlConnectionInternal_pendingSQLDNSObject =
38+ s_sqlConnectionInternal . GetField ( "pendingSQLDNSObject" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
39+
40+ // SQLDNSInfo
41+ private static readonly Type s_SQLDNSInfo = s_MicrosoftDotData . GetType ( "Microsoft.Data.SqlClient.SQLDNSInfo" ) ;
42+ private static readonly PropertyInfo s_SQLDNSInfo_AddrIPv4 =
43+ s_SQLDNSInfo . GetProperty ( "AddrIPv4" , BindingFlags . Instance | BindingFlags . Public ) ;
44+ private static readonly PropertyInfo s_SQLDNSInfo_AddrIPv6 =
45+ s_SQLDNSInfo . GetProperty ( "AddrIPv6" , BindingFlags . Instance | BindingFlags . Public ) ;
46+ private static readonly PropertyInfo s_SQLDNSInfo_FQDN =
47+ s_SQLDNSInfo . GetProperty ( "FQDN" , BindingFlags . Instance | BindingFlags . Public ) ;
48+ private static readonly PropertyInfo s_SQLDNSInfo_Port =
49+ s_SQLDNSInfo . GetProperty ( "Port" , BindingFlags . Instance | BindingFlags . Public ) ;
50+
51+ // TdsParser
52+ private static readonly Type s_tdsParser = s_MicrosoftDotData . GetType ( "Microsoft.Data.SqlClient.TdsParser" ) ;
53+ private static readonly FieldInfo s_tdsParser_physicalStateObj =
54+ s_tdsParser . GetField ( "_physicalStateObj" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
55+
56+ // TdsParserStateObject
57+ private static readonly Type s_tdsParserStateObject = s_MicrosoftDotData . GetType ( "Microsoft.Data.SqlClient.TdsParserStateObject" ) ;
58+ private static readonly FieldInfo s_tdsParserStateObject_enforcedTimeoutDelayInMilliSeconds =
59+ s_tdsParserStateObject . GetField ( "_enforcedTimeoutDelayInMilliSeconds" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
60+ private static readonly FieldInfo s_tdsParserStateObject_enforceTimeoutDelay =
61+ s_tdsParserStateObject . GetField ( "_enforceTimeoutDelay" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
3862
3963 public static object GetConnectionPool ( object internalConnection )
4064 {
4165 VerifyObjectIsInternalConnection ( internalConnection ) ;
42- return s_dbConnectionInternalPool . GetValue ( internalConnection , null ) ;
66+ return s_dbConnectionInternal_Pool . GetValue ( internalConnection , null ) ;
4367 }
4468
4569 public static object GetInternalConnection ( this SqlConnection connection )
4670 {
4771 VerifyObjectIsConnection ( connection ) ;
48- object internalConnection = s_sqlConnectionInternalConnection . GetValue ( connection , null ) ;
72+ object internalConnection = s_sqlConnection_InnerConnection . GetValue ( connection , null ) ;
4973 Debug . Assert ( ( ( internalConnection != null ) && ( s_dbConnectionInternal . IsInstanceOfType ( internalConnection ) ) ) , "Connection provided has an invalid internal connection" ) ;
5074 return internalConnection ;
5175 }
5276
5377 public static bool IsConnectionAlive ( object internalConnection )
5478 {
5579 VerifyObjectIsInternalConnection ( internalConnection ) ;
56- return ( bool ) s_dbConnectionInternalIsConnectionAlive . Invoke ( internalConnection , new object [ ] { false } ) ;
80+ return ( bool ) s_dbConnectionInternal_IsConnectionAlive . Invoke ( internalConnection , new object [ ] { false } ) ;
5781 }
5882
5983 private static void VerifyObjectIsInternalConnection ( object internalConnection )
@@ -85,36 +109,37 @@ private static void VerifyObjectIsConnection(object connection)
85109 public static bool IsEnlistedInTransaction ( object internalConnection )
86110 {
87111 VerifyObjectIsInternalConnection ( internalConnection ) ;
88- return ( dbConnectionInternalEnlistedTrans . GetValue ( internalConnection , null ) != null ) ;
112+ return ( s_sqlConnectionInternal_EnlistedTransaction . GetValue ( internalConnection , null ) != null ) ;
89113 }
90114
91115 public static bool IsTransactionRoot ( object internalConnection )
92116 {
93117 VerifyObjectIsInternalConnection ( internalConnection ) ;
94- return ( bool ) dbConnectionInternalIsTransRoot . GetValue ( internalConnection , null ) ;
118+ return ( bool ) s_dbConnectionInternal_IsTransationRoot . GetValue ( internalConnection , null ) ;
95119 }
96120
97121 public static bool IsTxRootWaitingForTxEnd ( object internalConnection )
98122 {
99123 VerifyObjectIsInternalConnection ( internalConnection ) ;
100- return ( bool ) dbConnectionInternalIsTxRootWaitingForTxEnd . GetValue ( internalConnection , null ) ;
124+ return ( bool ) s_dbConnectionInternal_IsTxRootWaitingForTxEnd . GetValue ( internalConnection , null ) ;
101125 }
102126
103127 public static object GetParser ( object internalConnection )
104128 {
105129 VerifyObjectIsInternalConnection ( internalConnection ) ;
106- return s_sqlInternalConnectionTdsParser . GetValue ( internalConnection ) ;
130+ return s_sqlConnectionInternal_Parser . GetValue ( internalConnection ) ;
107131 }
108132
109133 public static void SetEnforcedTimeout ( this SqlConnection connection , bool enforce , int timeout )
110134 {
111135 VerifyObjectIsConnection ( connection ) ;
112- var stateObj = s_tdsParserStateObjectProperty . GetValue (
113- s_tdsParserProperty . GetValue (
114- s_innerConnectionProperty . GetValue (
115- connection , null ) , null ) ) ;
116- s_enforceTimeoutDelayProperty . SetValue ( stateObj , enforce ) ;
117- s_enforcedTimeoutDelayInMilliSeconds . SetValue ( stateObj , timeout ) ;
136+
137+ var innerConnection = s_sqlConnection_InnerConnection . GetValue ( connection , null ) ;
138+ var parser = s_sqlConnectionInternal_Parser . GetValue ( innerConnection , null ) ;
139+ var stateObj = s_tdsParser_physicalStateObj . GetValue ( parser ) ;
140+
141+ s_tdsParserStateObject_enforceTimeoutDelay . SetValue ( stateObj , enforce ) ;
142+ s_tdsParserStateObject_enforcedTimeoutDelayInMilliSeconds . SetValue ( stateObj , timeout ) ;
118143 }
119144
120145 /// <summary>
@@ -126,11 +151,11 @@ public static Tuple<string, string, string, string> GetSQLDNSInfo(this SqlConnec
126151 {
127152 object internalConnection = GetInternalConnection ( connection ) ;
128153 VerifyObjectIsInternalConnection ( internalConnection ) ;
129- object pendingSQLDNSInfo = s_pendingSQLDNSObject . GetValue ( internalConnection ) ;
130- string fqdn = s_pendingSQLDNS_FQDN . GetValue ( pendingSQLDNSInfo ) as string ;
131- string ipv4 = s_pendingSQLDNS_AddrIPv4 . GetValue ( pendingSQLDNSInfo ) as string ;
132- string ipv6 = s_pendingSQLDNS_AddrIPv6 . GetValue ( pendingSQLDNSInfo ) as string ;
133- string port = s_pendingSQLDNS_Port . GetValue ( pendingSQLDNSInfo ) as string ;
154+ object pendingSQLDNSInfo = s_sqlConnectionInternal_pendingSQLDNSObject . GetValue ( internalConnection ) ;
155+ string fqdn = s_SQLDNSInfo_FQDN . GetValue ( pendingSQLDNSInfo ) as string ;
156+ string ipv4 = s_SQLDNSInfo_AddrIPv4 . GetValue ( pendingSQLDNSInfo ) as string ;
157+ string ipv6 = s_SQLDNSInfo_AddrIPv6 . GetValue ( pendingSQLDNSInfo ) as string ;
158+ string port = s_SQLDNSInfo_Port . GetValue ( pendingSQLDNSInfo ) as string ;
134159 return new Tuple < string , string , string , string > ( fqdn , ipv4 , ipv6 , port ) ;
135160 }
136161 }
0 commit comments