22
22
23
23
namespace Microsoft . Data . SqlClient
24
24
{
25
- internal sealed class SqlConnectionFactory : DbConnectionFactory
25
+ internal sealed class SqlConnectionFactory
26
26
{
27
27
#region Member Variables
28
28
@@ -180,13 +180,7 @@ internal DbConnectionPoolGroup GetConnectionPoolGroup(
180
180
// our collection of pool entries, then we need to create a
181
181
// new pool entry and add it to our collection.
182
182
183
- DbConnectionOptions connectionOptions = CreateConnectionOptions (
184
- key . ConnectionString ,
185
- userConnectionOptions ) ;
186
- if ( connectionOptions is null )
187
- {
188
- throw ADP . InternalConnectionError ( ADP . ConnectionError . ConnectionOptionsMissing ) ;
189
- }
183
+ SqlConnectionString connectionOptions = new SqlConnectionString ( key . ConnectionString ) ;
190
184
191
185
if ( userConnectionOptions is null )
192
186
{
@@ -474,58 +468,6 @@ internal bool TryGetConnection(
474
468
475
469
#endregion
476
470
477
- protected override DbConnectionOptions CreateConnectionOptions ( string connectionString , DbConnectionOptions previous )
478
- {
479
- Debug . Assert ( ! string . IsNullOrEmpty ( connectionString ) , "empty connectionString" ) ;
480
- SqlConnectionString result = new SqlConnectionString ( connectionString ) ;
481
- return result ;
482
- }
483
-
484
- protected override DbConnectionPoolGroupOptions CreateConnectionPoolGroupOptions ( DbConnectionOptions connectionOptions )
485
- {
486
- SqlConnectionString opt = ( SqlConnectionString ) connectionOptions ;
487
-
488
- DbConnectionPoolGroupOptions poolingOptions = null ;
489
-
490
- if ( opt . Pooling )
491
- { // never pool context connections.
492
- int connectionTimeout = opt . ConnectTimeout ;
493
-
494
- if ( connectionTimeout > 0 && connectionTimeout < int . MaxValue / 1000 )
495
- {
496
- connectionTimeout *= 1000 ;
497
- }
498
- else if ( connectionTimeout >= int . MaxValue / 1000 )
499
- {
500
- connectionTimeout = int . MaxValue ;
501
- }
502
-
503
- if ( opt . Authentication is SqlAuthenticationMethod . ActiveDirectoryInteractive
504
- or SqlAuthenticationMethod . ActiveDirectoryDeviceCodeFlow )
505
- {
506
- // interactive/device code flow mode will always have pool's CreateTimeout = 10 x ConnectTimeout.
507
- if ( connectionTimeout >= Int32 . MaxValue / 10 )
508
- {
509
- connectionTimeout = Int32 . MaxValue ;
510
- }
511
- else
512
- {
513
- connectionTimeout *= 10 ;
514
- }
515
- SqlClientEventSource . Log . TryTraceEvent ( "SqlConnectionFactory.CreateConnectionPoolGroupOptions | Set connection pool CreateTimeout '{0}' when Authentication mode '{1}' is used." , connectionTimeout , opt . Authentication ) ;
516
- }
517
-
518
- poolingOptions = new DbConnectionPoolGroupOptions (
519
- opt . IntegratedSecurity || opt . Authentication is SqlAuthenticationMethod . ActiveDirectoryIntegrated ,
520
- opt . MinPoolSize ,
521
- opt . MaxPoolSize ,
522
- connectionTimeout ,
523
- opt . LoadBalanceTimeout ,
524
- opt . Enlist ) ;
525
- }
526
- return poolingOptions ;
527
- }
528
-
529
471
internal DbConnectionPoolGroupProviderInfo CreateConnectionPoolGroupProviderInfo (
530
472
DbConnectionOptions connectionOptions ) =>
531
473
new SqlConnectionPoolGroupProviderInfo ( ( SqlConnectionString ) connectionOptions ) ;
@@ -556,7 +498,7 @@ internal SqlConnectionString FindSqlConnectionOptions(SqlConnectionPoolKey key)
556
498
}
557
499
558
500
// @TODO: All these methods seem redundant ... shouldn't we always have a SqlConnection?
559
- internal override DbConnectionPoolGroup GetConnectionPoolGroup ( DbConnection connection )
501
+ internal DbConnectionPoolGroup GetConnectionPoolGroup ( DbConnection connection )
560
502
{
561
503
SqlConnection c = ( connection as SqlConnection ) ;
562
504
if ( c != null )
@@ -566,7 +508,7 @@ internal override DbConnectionPoolGroup GetConnectionPoolGroup(DbConnection conn
566
508
return null ;
567
509
}
568
510
569
- internal override DbConnectionInternal GetInnerConnection ( DbConnection connection )
511
+ internal DbConnectionInternal GetInnerConnection ( DbConnection connection )
570
512
{
571
513
SqlConnection c = ( connection as SqlConnection ) ;
572
514
if ( c != null )
@@ -576,7 +518,7 @@ internal override DbConnectionInternal GetInnerConnection(DbConnection connectio
576
518
return null ;
577
519
}
578
520
579
- protected override int GetObjectId ( DbConnection connection )
521
+ internal int GetObjectId ( DbConnection connection )
580
522
{
581
523
SqlConnection c = ( connection as SqlConnection ) ;
582
524
if ( c != null )
@@ -586,7 +528,7 @@ protected override int GetObjectId(DbConnection connection)
586
528
return 0 ;
587
529
}
588
530
589
- internal override void PermissionDemand ( DbConnection outerConnection )
531
+ internal void PermissionDemand ( DbConnection outerConnection )
590
532
{
591
533
SqlConnection c = ( outerConnection as SqlConnection ) ;
592
534
if ( c != null )
@@ -595,7 +537,7 @@ internal override void PermissionDemand(DbConnection outerConnection)
595
537
}
596
538
}
597
539
598
- internal override void SetConnectionPoolGroup ( DbConnection outerConnection , DbConnectionPoolGroup poolGroup )
540
+ internal void SetConnectionPoolGroup ( DbConnection outerConnection , DbConnectionPoolGroup poolGroup )
599
541
{
600
542
SqlConnection c = ( outerConnection as SqlConnection ) ;
601
543
if ( c != null )
@@ -604,7 +546,7 @@ internal override void SetConnectionPoolGroup(DbConnection outerConnection, DbCo
604
546
}
605
547
}
606
548
607
- internal override void SetInnerConnectionEvent ( DbConnection owningObject , DbConnectionInternal to )
549
+ internal void SetInnerConnectionEvent ( DbConnection owningObject , DbConnectionInternal to )
608
550
{
609
551
SqlConnection c = ( owningObject as SqlConnection ) ;
610
552
if ( c != null )
@@ -613,7 +555,7 @@ internal override void SetInnerConnectionEvent(DbConnection owningObject, DbConn
613
555
}
614
556
}
615
557
616
- internal override bool SetInnerConnectionFrom ( DbConnection owningObject , DbConnectionInternal to , DbConnectionInternal from )
558
+ internal bool SetInnerConnectionFrom ( DbConnection owningObject , DbConnectionInternal to , DbConnectionInternal from )
617
559
{
618
560
SqlConnection c = ( owningObject as SqlConnection ) ;
619
561
if ( c != null )
@@ -623,7 +565,7 @@ internal override bool SetInnerConnectionFrom(DbConnection owningObject, DbConne
623
565
return false ;
624
566
}
625
567
626
- internal override void SetInnerConnectionTo ( DbConnection owningObject , DbConnectionInternal to )
568
+ internal void SetInnerConnectionTo ( DbConnection owningObject , DbConnectionInternal to )
627
569
{
628
570
SqlConnection c = ( owningObject as SqlConnection ) ;
629
571
if ( c != null )
@@ -757,6 +699,51 @@ private static SqlInternalConnectionTds CreateConnection(
757
699
key . AccessTokenCallback ) ;
758
700
}
759
701
702
+ private static DbConnectionPoolGroupOptions CreateConnectionPoolGroupOptions ( SqlConnectionString connectionOptions )
703
+ {
704
+ SqlConnectionString opt = ( SqlConnectionString ) connectionOptions ;
705
+
706
+ DbConnectionPoolGroupOptions poolingOptions = null ;
707
+
708
+ if ( opt . Pooling )
709
+ { // never pool context connections.
710
+ int connectionTimeout = opt . ConnectTimeout ;
711
+
712
+ if ( connectionTimeout > 0 && connectionTimeout < int . MaxValue / 1000 )
713
+ {
714
+ connectionTimeout *= 1000 ;
715
+ }
716
+ else if ( connectionTimeout >= int . MaxValue / 1000 )
717
+ {
718
+ connectionTimeout = int . MaxValue ;
719
+ }
720
+
721
+ if ( opt . Authentication is SqlAuthenticationMethod . ActiveDirectoryInteractive
722
+ or SqlAuthenticationMethod . ActiveDirectoryDeviceCodeFlow )
723
+ {
724
+ // interactive/device code flow mode will always have pool's CreateTimeout = 10 x ConnectTimeout.
725
+ if ( connectionTimeout >= Int32 . MaxValue / 10 )
726
+ {
727
+ connectionTimeout = Int32 . MaxValue ;
728
+ }
729
+ else
730
+ {
731
+ connectionTimeout *= 10 ;
732
+ }
733
+ SqlClientEventSource . Log . TryTraceEvent ( "SqlConnectionFactory.CreateConnectionPoolGroupOptions | Set connection pool CreateTimeout '{0}' when Authentication mode '{1}' is used." , connectionTimeout , opt . Authentication ) ;
734
+ }
735
+
736
+ poolingOptions = new DbConnectionPoolGroupOptions (
737
+ opt . IntegratedSecurity || opt . Authentication is SqlAuthenticationMethod . ActiveDirectoryIntegrated ,
738
+ opt . MinPoolSize ,
739
+ opt . MaxPoolSize ,
740
+ connectionTimeout ,
741
+ opt . LoadBalanceTimeout ,
742
+ opt . Enlist ) ;
743
+ }
744
+ return poolingOptions ;
745
+ }
746
+
760
747
private static DbMetaDataFactory CreateMetaDataFactory (
761
748
DbConnectionInternal internalConnection ,
762
749
out bool cacheMetaDataFactory )
0 commit comments