@@ -174,10 +174,6 @@ public SqlConnection(string connectionString, SqlCredential credential) : this()
174174 {
175175 throw ADP . InvalidMixedArgumentOfSecureCredentialAndIntegratedSecurity ( ) ;
176176 }
177- else if ( UsesContextConnection ( connectionOptions ) )
178- {
179- throw ADP . InvalidMixedArgumentOfSecureCredentialAndContextConnection ( ) ;
180- }
181177 else if ( UsesActiveDirectoryIntegrated ( connectionOptions ) )
182178 {
183179 throw SQL . SettingCredentialWithIntegratedArgument ( ) ;
@@ -459,49 +455,39 @@ public bool StatisticsEnabled
459455 }
460456 set
461457 {
462- if ( IsContextConnection )
458+ if ( value )
463459 {
464- if ( value )
460+ // start
461+ if ( ConnectionState . Open == State )
465462 {
466- throw SQL . NotAvailableOnContextConnection ( ) ;
463+ if ( _statistics == null )
464+ {
465+ _statistics = new SqlStatistics ( ) ;
466+ _statistics . _openTimestamp = ADP . TimerCurrent ( ) ;
467+ }
468+ // set statistics on the parser
469+ // update timestamp;
470+ Debug . Assert ( Parser != null , "Where's the parser?" ) ;
471+ Parser . Statistics = _statistics ;
467472 }
468473 }
469474 else
470475 {
471- if ( value )
476+ // stop
477+ if ( _statistics != null )
472478 {
473- // start
474479 if ( ConnectionState . Open == State )
475480 {
476- if ( _statistics == null )
477- {
478- _statistics = new SqlStatistics ( ) ;
479- _statistics . _openTimestamp = ADP . TimerCurrent ( ) ;
480- }
481- // set statistics on the parser
481+ // remove statistics from parser
482482 // update timestamp;
483- Debug . Assert ( Parser != null , "Where's the parser?" ) ;
484- Parser . Statistics = _statistics ;
483+ TdsParser parser = Parser ;
484+ Debug . Assert ( parser != null , "Where's the parser?" ) ;
485+ parser . Statistics = null ;
486+ _statistics . _closeTimestamp = ADP . TimerCurrent ( ) ;
485487 }
486488 }
487- else
488- {
489- // stop
490- if ( _statistics != null )
491- {
492- if ( ConnectionState . Open == State )
493- {
494- // remove statistics from parser
495- // update timestamp;
496- TdsParser parser = Parser ;
497- Debug . Assert ( parser != null , "Where's the parser?" ) ;
498- parser . Statistics = null ;
499- _statistics . _closeTimestamp = ADP . TimerCurrent ( ) ;
500- }
501- }
502- }
503- _collectstats = value ;
504489 }
490+ _collectstats = value ;
505491 }
506492 }
507493
@@ -512,21 +498,6 @@ internal bool AsyncCommandInProgress
512498 set => _AsyncCommandInProgress = value ;
513499 }
514500
515- internal bool IsContextConnection
516- {
517- get
518- {
519- SqlConnectionString opt = ( SqlConnectionString ) ConnectionOptions ;
520- return UsesContextConnection ( opt ) ;
521- }
522- }
523-
524- // Is this connection is a Context Connection?
525- private bool UsesContextConnection ( SqlConnectionString opt )
526- {
527- return opt != null && opt . ContextConnection ;
528- }
529-
530501 private bool UsesActiveDirectoryIntegrated ( SqlConnectionString opt )
531502 {
532503 return opt != null && opt . Authentication == SqlAuthenticationMethod . ActiveDirectoryIntegrated ;
@@ -868,15 +839,8 @@ public int PacketSize
868839 // can just return what the connection string had.
869840 get
870841 {
871- if ( IsContextConnection )
872- {
873- throw SQL . NotAvailableOnContextConnection ( ) ;
874- }
875-
876- SqlInternalConnectionTds innerConnection = ( InnerConnection as SqlInternalConnectionTds ) ;
877842 int result ;
878-
879- if ( innerConnection != null )
843+ if ( InnerConnection is SqlInternalConnectionTds innerConnection )
880844 {
881845 result = innerConnection . PacketSize ;
882846 }
@@ -885,6 +849,7 @@ public int PacketSize
885849 SqlConnectionString constr = ( SqlConnectionString ) ConnectionOptions ;
886850 result = constr != null ? constr . PacketSize : SqlConnectionString . DEFAULT . Packet_Size ;
887851 }
852+
888853 return result ;
889854 }
890855 }
@@ -970,11 +935,6 @@ public string WorkstationId
970935 {
971936 get
972937 {
973- if ( IsContextConnection )
974- {
975- throw SQL . NotAvailableOnContextConnection ( ) ;
976- }
977-
978938 // If not supplied by the user, the default value is the MachineName
979939 // Note: In Longhorn you'll be able to rename a machine without
980940 // rebooting. Therefore, don't cache this machine name.
@@ -1086,11 +1046,6 @@ private void CheckAndThrowOnInvalidCombinationOfConnectionStringAndSqlCredential
10861046 {
10871047 throw ADP . InvalidMixedUsageOfSecureCredentialAndIntegratedSecurity ( ) ;
10881048 }
1089-
1090- if ( UsesContextConnection ( connectionOptions ) )
1091- {
1092- throw ADP . InvalidMixedArgumentOfSecureCredentialAndContextConnection ( ) ;
1093- }
10941049 }
10951050
10961051 // CheckAndThrowOnInvalidCombinationOfConnectionOptionAndAccessToken: check if the usage of AccessToken has any conflict
@@ -1109,11 +1064,6 @@ private void CheckAndThrowOnInvalidCombinationOfConnectionOptionAndAccessToken(S
11091064 throw ADP . InvalidMixedUsageOfAccessTokenAndIntegratedSecurity ( ) ;
11101065 }
11111066
1112- if ( UsesContextConnection ( connectionOptions ) )
1113- {
1114- throw ADP . InvalidMixedUsageOfAccessTokenAndContextConnection ( ) ;
1115- }
1116-
11171067 if ( UsesAuthentication ( connectionOptions ) )
11181068 {
11191069 throw ADP . InvalidMixedUsageOfAccessTokenAndAuthentication ( ) ;
@@ -1328,10 +1278,6 @@ public static void ClearPool(SqlConnection connection)
13281278 if ( connectionOptions != null )
13291279 {
13301280 connectionOptions . DemandPermission ( ) ;
1331- if ( connection . IsContextConnection )
1332- {
1333- throw SQL . NotAvailableOnContextConnection ( ) ;
1334- }
13351281 SqlConnectionFactory . SingletonInstance . ClearPool ( connection ) ;
13361282 }
13371283 }
@@ -1446,21 +1392,12 @@ private void DisposeMe(bool disposing)
14461392 }
14471393
14481394 /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml' path='docs/members[@name="SqlConnection"]/EnlistDistributedTransaction/*' />
1449- public void EnlistDistributedTransaction ( System . EnterpriseServices . ITransaction transaction )
1450- {
1451- if ( IsContextConnection )
1452- {
1453- throw SQL . NotAvailableOnContextConnection ( ) ;
1454- }
1455-
1395+ public void EnlistDistributedTransaction ( System . EnterpriseServices . ITransaction transaction ) =>
14561396 EnlistDistributedTransactionHelper ( transaction ) ;
1457- }
14581397
14591398 /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml' path='docs/members[@name="SqlConnection"]/Open/*' />
1460- public override void Open ( )
1461- {
1399+ public override void Open ( ) =>
14621400 Open ( SqlConnectionOverrides . None ) ;
1463- }
14641401
14651402 private bool TryOpenWithRetry ( TaskCompletionSource < DbConnectionInternal > retry , SqlConnectionOverrides overrides )
14661403 => RetryLogicProvider . Execute ( this , ( ) => TryOpen ( retry , overrides ) ) ;
@@ -1773,13 +1710,6 @@ private Task InternalOpenAsync(SqlConnectionOverrides overrides, CancellationTok
17731710 return result . Task ;
17741711 }
17751712
1776- if ( IsContextConnection )
1777- {
1778- // Async not supported on Context Connections
1779- result . SetException ( ADP . ExceptionWithStackTrace ( SQL . NotAvailableOnContextConnection ( ) ) ) ;
1780- return result . Task ;
1781- }
1782-
17831713 bool completed ;
17841714
17851715 try
@@ -2275,12 +2205,8 @@ public static void ChangePassword(string connectionString, string newPassword)
22752205 {
22762206 throw SQL . ChangePasswordUseOfUnallowedKey ( SqlConnectionString . KEY . AttachDBFilename ) ;
22772207 }
2278- if ( connectionOptions . ContextConnection )
2279- {
2280- throw SQL . ChangePasswordUseOfUnallowedKey ( SqlConnectionString . KEY . Context_Connection ) ;
2281- }
22822208
2283- System . Security . PermissionSet permissionSet = connectionOptions . CreatePermissionSet ( ) ;
2209+ PermissionSet permissionSet = connectionOptions . CreatePermissionSet ( ) ;
22842210 permissionSet . Demand ( ) ;
22852211
22862212 ChangePassword ( connectionString , connectionOptions , null , newPassword , null ) ;
@@ -2340,12 +2266,7 @@ public static void ChangePassword(string connectionString, SqlCredential credent
23402266 throw SQL . ChangePasswordUseOfUnallowedKey ( SqlConnectionString . KEY . AttachDBFilename ) ;
23412267 }
23422268
2343- if ( connectionOptions . ContextConnection )
2344- {
2345- throw SQL . ChangePasswordUseOfUnallowedKey ( SqlConnectionString . KEY . Context_Connection ) ;
2346- }
2347-
2348- System . Security . PermissionSet permissionSet = connectionOptions . CreatePermissionSet ( ) ;
2269+ PermissionSet permissionSet = connectionOptions . CreatePermissionSet ( ) ;
23492270 permissionSet . Demand ( ) ;
23502271
23512272 ChangePassword ( connectionString , connectionOptions , credential , null , newSecurePassword ) ;
@@ -2419,11 +2340,6 @@ internal Task<T> RegisterForConnectionCloseNotification<T>(Task<T> outerTask, ob
24192340 /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml' path='docs/members[@name="SqlConnection"]/ResetStatistics/*' />
24202341 public void ResetStatistics ( )
24212342 {
2422- if ( IsContextConnection )
2423- {
2424- throw SQL . NotAvailableOnContextConnection ( ) ;
2425- }
2426-
24272343 if ( Statistics != null )
24282344 {
24292345 Statistics . Reset ( ) ;
@@ -2438,11 +2354,6 @@ public void ResetStatistics()
24382354 /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml' path='docs/members[@name="SqlConnection"]/RetrieveStatistics/*' />
24392355 public IDictionary RetrieveStatistics ( )
24402356 {
2441- if ( IsContextConnection )
2442- {
2443- throw SQL . NotAvailableOnContextConnection ( ) ;
2444- }
2445-
24462357 if ( Statistics != null )
24472358 {
24482359 UpdateStatistics ( ) ;
0 commit comments