@@ -63,10 +63,10 @@ internal static class DEFAULT
6363 internal static readonly SqlConnectionIPAddressPreference IpAddressPreference = DbConnectionStringDefaults . IPAddressPreference ;
6464 internal const string ServerSPN = DbConnectionStringDefaults . ServerSPN ;
6565 internal const string FailoverPartnerSPN = DbConnectionStringDefaults . FailoverPartnerSPN ;
66+ internal const bool Context_Connection = DbConnectionStringDefaults . ContextConnection ;
6667#if NETFRAMEWORK
6768 internal static readonly bool TransparentNetworkIPResolution = DbConnectionStringDefaults . TransparentNetworkIPResolution ;
6869 internal const bool Connection_Reset = DbConnectionStringDefaults . ConnectionReset ;
69- internal const bool Context_Connection = DbConnectionStringDefaults . ContextConnection ;
7070 internal const string Network_Library = DbConnectionStringDefaults . NetworkLibrary ;
7171#endif // NETFRAMEWORK
7272 }
@@ -261,6 +261,7 @@ internal static class TRANSACTIONBINDING
261261 private readonly ApplicationIntent _applicationIntent ;
262262 private readonly string _applicationName ;
263263 private readonly string _attachDBFileName ;
264+ private readonly bool _contextConnection ;
264265 private readonly string _currentLanguage ;
265266 private readonly string _dataSource ;
266267 private readonly string _localDBInstance ; // created based on datasource, set to NULL if datasource is not LocalDB
@@ -289,11 +290,8 @@ internal static class TRANSACTIONBINDING
289290 [ ResourceConsumption ( ResourceScope . Machine , ResourceScope . Machine ) ]
290291 internal SqlConnectionString ( string connectionString ) : base ( connectionString , GetParseSynonyms ( ) )
291292 {
292- #if NETFRAMEWORK
293- bool runningInProc = InOutOfProcHelper . InProc ;
294- #else
293+ #if ! NETFRAMEWORK
295294 ThrowUnsupportedIfKeywordSet ( KEY . Connection_Reset ) ;
296- ThrowUnsupportedIfKeywordSet ( KEY . Context_Connection ) ;
297295
298296 // Network Library has its own special error message
299297 if ( ContainsKey ( KEY . Network_Library ) )
@@ -325,6 +323,7 @@ internal SqlConnectionString(string connectionString) : base(connectionString, G
325323 _applicationIntent = ConvertValueToApplicationIntent ( ) ;
326324 _applicationName = ConvertValueToString ( KEY . Application_Name , DEFAULT . Application_Name ) ;
327325 _attachDBFileName = ConvertValueToString ( KEY . AttachDBFilename , DEFAULT . AttachDBFilename ) ;
326+ _contextConnection = ConvertValueToBoolean ( KEY . Context_Connection , DEFAULT . Context_Connection ) ;
328327 _currentLanguage = ConvertValueToString ( KEY . Current_Language , DEFAULT . Current_Language ) ;
329328 _dataSource = ConvertValueToString ( KEY . Data_Source , DEFAULT . Data_Source ) ;
330329 _localDBInstance = LocalDBAPI . GetLocalDbInstanceNameFromServerName ( _dataSource ) ;
@@ -349,6 +348,11 @@ internal SqlConnectionString(string connectionString) : base(connectionString, G
349348 _userID = ConvertValueToString ( KEY . User_ID , DEFAULT . User_ID ) ;
350349 _workstationId = ConvertValueToString ( KEY . Workstation_Id , null ) ;
351350
351+ if ( _contextConnection )
352+ {
353+ throw SQL . ContextConnectionIsUnsupported ( ) ;
354+ }
355+
352356 if ( _loadBalanceTimeout < 0 )
353357 {
354358 throw ADP . InvalidConnectionOptionValue ( KEY . Load_Balance_Timeout ) ;
@@ -386,35 +390,9 @@ internal SqlConnectionString(string connectionString) : base(connectionString, G
386390#if NETFRAMEWORK
387391 // SQLPT 41700: Ignore ResetConnection=False (still validate the keyword/value)
388392 _connectionReset = ConvertValueToBoolean ( KEY . Connection_Reset , DEFAULT . Connection_Reset ) ;
389- _contextConnection = ConvertValueToBoolean ( KEY . Context_Connection , DEFAULT . Context_Connection ) ;
390- _encrypt = ConvertValueToSqlConnectionEncrypt ( ) ;
391- _enlist = ConvertValueToBoolean ( KEY . Enlist , ADP . s_isWindowsNT ) ;
392393 _transparentNetworkIPResolution = ConvertValueToBoolean ( KEY . TransparentNetworkIPResolution , DEFAULT . TransparentNetworkIPResolution ) ;
393394 _networkLibrary = ConvertValueToString ( KEY . Network_Library , null ) ;
394395
395- if ( _contextConnection )
396- {
397- // We have to be running in the engine for you to request a
398- // context connection.
399-
400- if ( ! runningInProc )
401- {
402- throw SQL . ContextUnavailableOutOfProc ( ) ;
403- }
404-
405- // When using a context connection, we need to ensure that no
406- // other connection string keywords are specified.
407-
408- foreach ( KeyValuePair < string , string > entry in Parsetable )
409- {
410- if ( entry . Key != KEY . Context_Connection &&
411- entry . Key != KEY . Type_System_Version )
412- {
413- throw SQL . ContextAllowsLimitedKeywords ( ) ;
414- }
415- }
416- }
417-
418396 if ( _networkLibrary != null )
419397 { // MDAC 83525
420398 string networkLibrary = _networkLibrary . Trim ( ) . ToLower ( CultureInfo . InvariantCulture ) ;
@@ -522,12 +500,6 @@ internal SqlConnectionString(string connectionString) : base(connectionString, G
522500 }
523501 else if ( typeSystemVersionString . Equals ( TYPESYSTEMVERSION . SQL_Server_2000 , StringComparison . OrdinalIgnoreCase ) )
524502 {
525- #if NETFRAMEWORK
526- if ( _contextConnection )
527- {
528- throw SQL . ContextAllowsOnlyTypeSystem2005 ( ) ;
529- }
530- #endif
531503 _typeSystemVersion = TypeSystem . SQLServer2000 ;
532504 }
533505 else if ( typeSystemVersionString . Equals ( TYPESYSTEMVERSION . SQL_Server_2005 , StringComparison . OrdinalIgnoreCase ) )
@@ -653,6 +625,7 @@ internal SqlConnectionString(SqlConnectionString connectionOptions, string dataS
653625 _packetSize = connectionOptions . _packetSize ;
654626 _applicationName = connectionOptions . _applicationName ;
655627 _attachDBFileName = connectionOptions . _attachDBFileName ;
628+ _contextConnection = connectionOptions . _contextConnection ;
656629 _currentLanguage = connectionOptions . _currentLanguage ;
657630 _dataSource = dataSource ;
658631 _localDBInstance = LocalDBAPI . GetLocalDbInstanceNameFromServerName ( _dataSource ) ;
@@ -676,7 +649,6 @@ internal SqlConnectionString(SqlConnectionString connectionOptions, string dataS
676649 _hostNameInCertificate = connectionOptions . _hostNameInCertificate ;
677650#if NETFRAMEWORK
678651 _connectionReset = connectionOptions . _connectionReset ;
679- _contextConnection = connectionOptions . _contextConnection ;
680652 _transparentNetworkIPResolution = connectionOptions . _transparentNetworkIPResolution ;
681653 _networkLibrary = connectionOptions . _networkLibrary ;
682654 _typeSystemAssemblyVersion = connectionOptions . _typeSystemAssemblyVersion ;
@@ -721,6 +693,9 @@ internal SqlConnectionString(SqlConnectionString connectionOptions, string dataS
721693 internal ApplicationIntent ApplicationIntent => _applicationIntent ;
722694 internal string ApplicationName => _applicationName ;
723695 internal string AttachDBFilename => _attachDBFileName ;
696+ // Return a constant value rather than _contextConnection. This allows the JIT to trim
697+ // the code paths referencing it.
698+ internal bool ContextConnection => false ;
724699 internal string CurrentLanguage => _currentLanguage ;
725700 internal string DataSource => _dataSource ;
726701 internal string LocalDBInstance => _localDBInstance ;
@@ -1192,11 +1167,9 @@ internal SqlConnectionEncryptOption ConvertValueToEncrypt()
11921167 }
11931168
11941169 private readonly bool _connectionReset ;
1195- private readonly bool _contextConnection ;
11961170 private readonly bool _transparentNetworkIPResolution ;
11971171 private readonly string _networkLibrary ;
11981172
1199- internal bool ContextConnection => _contextConnection ;
12001173 internal bool TransparentNetworkIPResolution => _transparentNetworkIPResolution ;
12011174 internal string NetworkLibrary => _networkLibrary ;
12021175
0 commit comments