Skip to content

Commit 25d580d

Browse files
committed
Move GetConnectionPool
1 parent e5d42d9 commit 25d580d

File tree

2 files changed

+36
-35
lines changed

2 files changed

+36
-35
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,41 +47,6 @@ protected static Task<DbConnectionInternal> GetCompletedTask()
4747
return s_completedTask ?? (s_completedTask = Task.FromResult<DbConnectionInternal>(null));
4848
}
4949

50-
protected IDbConnectionPool GetConnectionPool(DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup)
51-
{
52-
// if poolgroup is disabled, it will be replaced with a new entry
53-
54-
Debug.Assert(owningObject != null, "null owningObject?");
55-
Debug.Assert(connectionPoolGroup != null, "null connectionPoolGroup?");
56-
57-
// It is possible that while the outer connection object has
58-
// been sitting around in a closed and unused state in some long
59-
// running app, the pruner may have come along and remove this
60-
// the pool entry from the master list. If we were to use a
61-
// pool entry in this state, we would create "unmanaged" pools,
62-
// which would be bad. To avoid this problem, we automagically
63-
// re-create the pool entry whenever it's disabled.
64-
65-
// however, don't rebuild connectionOptions if no pooling is involved - let new connections do that work
66-
if (connectionPoolGroup.IsDisabled && connectionPoolGroup.PoolGroupOptions != null)
67-
{
68-
SqlClientEventSource.Log.TryTraceEvent("<prov.DbConnectionFactory.GetConnectionPool|RES|INFO|CPOOL> {0}, DisabledPoolGroup={1}", ObjectID, connectionPoolGroup?.ObjectID);
69-
70-
// reusing existing pool option in case user originally used SetConnectionPoolOptions
71-
DbConnectionPoolGroupOptions poolOptions = connectionPoolGroup.PoolGroupOptions;
72-
73-
// get the string to hash on again
74-
DbConnectionOptions connectionOptions = connectionPoolGroup.ConnectionOptions;
75-
Debug.Assert(connectionOptions != null, "prevent expansion of connectionString");
76-
77-
connectionPoolGroup = GetConnectionPoolGroup(connectionPoolGroup.PoolKey, poolOptions, ref connectionOptions);
78-
Debug.Assert(connectionPoolGroup != null, "null connectionPoolGroup?");
79-
SetConnectionPoolGroup(owningObject, connectionPoolGroup);
80-
}
81-
IDbConnectionPool connectionPool = connectionPoolGroup.GetConnectionPool((SqlConnectionFactory)this);
82-
return connectionPool;
83-
}
84-
8550
internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, ref DbConnectionOptions userConnectionOptions)
8651
{
8752
if (string.IsNullOrEmpty(key.ConnectionString))

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,42 @@ private Task<DbConnectionInternal> CreateReplaceConnectionContinuation(
669669
);
670670
}
671671

672+
private IDbConnectionPool GetConnectionPool(
673+
DbConnection owningObject,
674+
DbConnectionPoolGroup connectionPoolGroup)
675+
{
676+
// If poolgroup is disabled, it will be replaced with a new entry
677+
678+
Debug.Assert(owningObject != null, "null owningObject?");
679+
Debug.Assert(connectionPoolGroup != null, "null connectionPoolGroup?");
680+
681+
// It is possible that while the outer connection object has been sitting around in a
682+
// closed and unused state in some long-running app, the pruner may have come along and
683+
// remove this the pool entry from the master list. If we were to use a pool entry in
684+
// this state, we would create "unmanaged" pools, which would be bad. To avoid this
685+
// problem, we automagically re-create the pool entry whenever it's disabled.
686+
687+
// however, don't rebuild connectionOptions if no pooling is involved - let new connections do that work
688+
if (connectionPoolGroup.IsDisabled && connectionPoolGroup.PoolGroupOptions != null)
689+
{
690+
SqlClientEventSource.Log.TryTraceEvent("<prov.SqlConnectionFactory.GetConnectionPool|RES|INFO|CPOOL> {0}, DisabledPoolGroup={1}", ObjectId, connectionPoolGroup.ObjectID);
691+
692+
// reusing existing pool option in case user originally used SetConnectionPoolOptions
693+
DbConnectionPoolGroupOptions poolOptions = connectionPoolGroup.PoolGroupOptions;
694+
695+
// get the string to hash on again
696+
DbConnectionOptions connectionOptions = connectionPoolGroup.ConnectionOptions;
697+
Debug.Assert(connectionOptions != null, "prevent expansion of connectionString");
698+
699+
connectionPoolGroup = GetConnectionPoolGroup(connectionPoolGroup.PoolKey, poolOptions, ref connectionOptions);
700+
Debug.Assert(connectionPoolGroup != null, "null connectionPoolGroup?");
701+
SetConnectionPoolGroup(owningObject, connectionPoolGroup);
702+
}
703+
704+
IDbConnectionPool connectionPool = connectionPoolGroup.GetConnectionPool(this);
705+
return connectionPool;
706+
}
707+
672708
private void TryGetConnectionCompletedContinuation(Task<DbConnectionInternal> task, object state)
673709
{
674710
// Decompose the state into the parameters we want

0 commit comments

Comments
 (0)