Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ protected internal override Task<DataTable> GetSchemaAsync(
internal override bool TryOpenConnection(
DbConnection outerConnection,
SqlConnectionFactory connectionFactory,
TaskCompletionSource<DbConnectionInternal> retry,
SqlConnectionOptions userOptions) =>
TryOpenConnectionInternal(outerConnection, connectionFactory, retry, userOptions);
TaskCompletionSource<DbConnectionInternal> retry) =>
TryOpenConnectionInternal(outerConnection, connectionFactory, retry);

/// <inheritdoc/>
internal override void ResetConnection() => throw ADP.ClosedConnectionError();
Expand All @@ -79,8 +78,7 @@ protected DbConnectionBusy(ConnectionState state) : base(state, true, false)
internal override bool TryOpenConnection(
DbConnection outerConnection,
SqlConnectionFactory connectionFactory,
TaskCompletionSource<DbConnectionInternal> retry,
SqlConnectionOptions userOptions)
TaskCompletionSource<DbConnectionInternal> retry)
=> throw ADP.ConnectionAlreadyOpen(State);
}

Expand Down Expand Up @@ -121,15 +119,13 @@ internal override void CloseConnection(DbConnection owningObject, SqlConnectionF
internal override bool TryReplaceConnection(
DbConnection outerConnection,
SqlConnectionFactory connectionFactory,
TaskCompletionSource<DbConnectionInternal> retry,
SqlConnectionOptions userOptions) =>
TryOpenConnection(outerConnection, connectionFactory, retry, userOptions);
TaskCompletionSource<DbConnectionInternal> retry) =>
TryOpenConnection(outerConnection, connectionFactory, retry);

internal override bool TryOpenConnection(
DbConnection outerConnection,
SqlConnectionFactory connectionFactory,
TaskCompletionSource<DbConnectionInternal> retry,
SqlConnectionOptions userOptions)
TaskCompletionSource<DbConnectionInternal> retry)
{
if (retry == null || !retry.Task.IsCompleted)
{
Expand Down Expand Up @@ -177,8 +173,7 @@ private DbConnectionClosedPreviouslyOpened() : base(ConnectionState.Closed, true
internal override bool TryReplaceConnection(
DbConnection outerConnection,
SqlConnectionFactory connectionFactory,
TaskCompletionSource<DbConnectionInternal> retry,
SqlConnectionOptions userOptions) =>
TryOpenConnection(outerConnection, connectionFactory, retry, userOptions);
TaskCompletionSource<DbConnectionInternal> retry) =>
TryOpenConnection(outerConnection, connectionFactory, retry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ internal void MakePooledConnection(IDbConnectionPool connectionPool)

internal virtual void OpenConnection(DbConnection outerConnection, SqlConnectionFactory connectionFactory)
{
if (!TryOpenConnection(outerConnection, connectionFactory, null, null))
if (!TryOpenConnection(outerConnection, connectionFactory, null))
{
throw ADP.InternalError(ADP.InternalErrorCode.SynchronousConnectReturnedPending);
}
Expand Down Expand Up @@ -800,17 +800,15 @@ internal void SetInStasis()
internal virtual bool TryOpenConnection(
DbConnection outerConnection,
SqlConnectionFactory connectionFactory,
TaskCompletionSource<DbConnectionInternal> retry,
SqlConnectionOptions userOptions)
TaskCompletionSource<DbConnectionInternal> retry)
{
throw ADP.ConnectionAlreadyOpen(State);
}

internal virtual bool TryReplaceConnection(
DbConnection outerConnection,
SqlConnectionFactory connectionFactory,
TaskCompletionSource<DbConnectionInternal> retry,
SqlConnectionOptions userOptions)
TaskCompletionSource<DbConnectionInternal> retry)
{
throw ADP.MethodNotImplemented();
}
Expand Down Expand Up @@ -912,8 +910,7 @@ protected virtual void ReleaseAdditionalLocksForClose(bool lockToken)
protected bool TryOpenConnectionInternal(
DbConnection outerConnection,
SqlConnectionFactory connectionFactory,
TaskCompletionSource<DbConnectionInternal> retry,
SqlConnectionOptions userOptions)
TaskCompletionSource<DbConnectionInternal> retry)
{
// ?->Connecting: prevent set_ConnectionString during Open
if (connectionFactory.SetInnerConnectionFrom(outerConnection, DbConnectionClosedConnecting.SingletonInstance, this))
Expand All @@ -922,7 +919,7 @@ protected bool TryOpenConnectionInternal(
try
{
connectionFactory.PermissionDemand(outerConnection);
if (!connectionFactory.TryGetConnection(outerConnection, retry, userOptions, this, out openConnection))
if (!connectionFactory.TryGetConnection(outerConnection, retry, this, out openConnection))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,6 @@ internal class SqlConnectionInternal : DbConnectionInternal, IDisposable
/// - Although the new password is generally not used it must be passed to the ctor. The
/// new Login7 packet will always write out the new password (or a length of zero and no
/// bytes if not present).
/// - userConnectionOptions may be different to connectionOptions if the connection string
/// has been expanded (see SqlConnectionOptions.Expand)
/// </remarks>
// @TODO: We really really need simplify what we pass into this. All these optional parameters need to go!
internal SqlConnectionInternal(
Expand All @@ -324,7 +322,6 @@ internal SqlConnectionInternal(
string newPassword,
SecureString newSecurePassword,
bool redirectedUserInstance,
SqlConnectionOptions userConnectionOptions = null,
SessionData reconnectSessionData = null,
bool applyTransientFaultHandling = false,
string accessToken = null,
Expand All @@ -341,29 +338,6 @@ internal SqlConnectionInternal(
{
reconnectSessionData._debugReconnectDataApplied = true;
}

#if NETFRAMEWORK
try
{
// use this to help validate this object is only created after the following
// permission has been previously demanded in the current codepath
if (userConnectionOptions != null)
{
// As mentioned above, userConnectionOptions may be different to
// connectionOptions, so we need to demand on the correct connection string
userConnectionOptions.DemandPermission();
Comment thread
mdaigle marked this conversation as resolved.
}
else
{
connectionOptions.DemandPermission();
}
}
catch (SecurityException)
{
Debug.Assert(false, "unexpected SecurityException for current codepath");
throw;
}
#endif
#endif

Debug.Assert(reconnectSessionData == null || connectionOptions.ConnectRetryCount > 0,
Expand Down Expand Up @@ -1970,10 +1944,9 @@ internal void OnLoginAck(SqlLoginAck rec)
internal override bool TryReplaceConnection(
DbConnection outerConnection,
SqlConnectionFactory connectionFactory,
TaskCompletionSource<DbConnectionInternal> retry,
SqlConnectionOptions userOptions)
TaskCompletionSource<DbConnectionInternal> retry)
{
return TryOpenConnectionInternal(outerConnection, connectionFactory, retry, userOptions);
return TryOpenConnectionInternal(outerConnection, connectionFactory, retry);
}

internal void ValidateConnectionForExecute(SqlCommand command)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ public void PutObjectFromTransactedPool(DbConnectionInternal connection)
/// <inheritdoc />
public DbConnectionInternal ReplaceConnection(
DbConnection owningObject,
SqlConnectionOptions userOptions,
DbConnectionInternal oldConnection)
{
throw new NotImplementedException();
Expand Down Expand Up @@ -282,7 +281,6 @@ public void TransactionEnded(Transaction transaction, DbConnectionInternal trans
public bool TryGetConnection(
DbConnection owningObject,
TaskCompletionSource<DbConnectionInternal>? taskCompletionSource,
SqlConnectionOptions userOptions,
out DbConnectionInternal? connection)
{
var timeout = TimeSpan.FromSeconds(owningObject.ConnectionTimeout);
Expand All @@ -292,7 +290,6 @@ public bool TryGetConnection(
{
var task = GetInternalConnection(
owningObject,
userOptions,
async: false,
timeout);

Expand Down Expand Up @@ -340,7 +337,6 @@ public bool TryGetConnection(
{
connection = await GetInternalConnection(
owningObject,
userOptions,
async: true,
timeout
).ConfigureAwait(false);
Expand Down Expand Up @@ -375,15 +371,13 @@ public bool TryGetConnection(
/// Opens a new internal connection to the database.
/// </summary>
/// <param name="owningConnection">The owning connection.</param>
/// <param name="userOptions">The options for the connection.</param>
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
/// <returns>A task representing the asynchronous operation, with a result of the new internal connection.</returns>
/// <exception cref="OperationCanceledException">
/// Thrown when the cancellation token is cancelled before the connection operation completes.
/// </exception>
private DbConnectionInternal? OpenNewInternalConnection(
DbConnection? owningConnection,
SqlConnectionOptions userOptions,
CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
Expand All @@ -405,8 +399,7 @@ public bool TryGetConnection(
// when this support is added to DbConnectionInternal.
var connection = ConnectionFactory.CreatePooledConnection(
owningConnection,
Comment thread
mdaigle marked this conversation as resolved.
this,
userOptions);
this);

if (connection is not null)
{
Expand Down Expand Up @@ -498,7 +491,6 @@ private void RemoveConnection(DbConnectionInternal connection)
/// Gets an internal connection from the pool, either by retrieving an idle connection or opening a new one.
/// </summary>
/// <param name="owningConnection">The DbConnection that will own this internal connection</param>
/// <param name="userOptions">The user options to set on the internal connection</param>
/// <param name="async">A boolean indicating whether the operation should be asynchronous.</param>
/// <param name="timeout">The timeout for the operation.</param>
/// <returns>Returns a DbConnectionInternal that is retrieved from the pool.</returns>
Expand All @@ -512,7 +504,6 @@ private void RemoveConnection(DbConnectionInternal connection)
/// </exception>
private async Task<DbConnectionInternal> GetInternalConnection(
DbConnection owningConnection,
SqlConnectionOptions userOptions,
bool async,
TimeSpan timeout)
{
Expand All @@ -533,7 +524,6 @@ private async Task<DbConnectionInternal> GetInternalConnection(
// If we didn't find an idle connection, try to open a new one.
connection ??= OpenNewInternalConnection(
owningConnection,
userOptions,
cancellationToken);

// If we're at max capacity and couldn't open a connection. Block on the idle channel with a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,17 @@ internal interface IDbConnectionPool
/// <param name="owningObject">The SqlConnection that will own this internal connection.</param>
/// <param name="taskCompletionSource">Used when calling this method in an async context.
/// The internal connection will be set on completion source rather than passed out via the out parameter.</param>
/// <param name="userOptions">The user options to use if a new connection must be opened.</param>
/// <param name="connection">The retrieved connection will be passed out via this parameter.</param>
/// <returns>True if a connection was set in the out parameter, otherwise returns false.</returns>
bool TryGetConnection(DbConnection owningObject, TaskCompletionSource<DbConnectionInternal>? taskCompletionSource, SqlConnectionOptions userOptions, out DbConnectionInternal? connection);
bool TryGetConnection(DbConnection owningObject, TaskCompletionSource<DbConnectionInternal>? taskCompletionSource, out DbConnectionInternal? connection);

/// <summary>
/// Replaces the internal connection currently associated with owningObject with a new internal connection from the pool.
/// </summary>
/// <param name="owningObject">The connection whos internal connection should be replaced.</param>
/// <param name="userOptions">The user options to use if a new connection must be opened.</param>
/// <param name="owningObject">The connection whose internal connection should be replaced.</param>
/// <param name="oldConnection">The internal connection currently associated with the owning object.</param>
/// <returns>A reference to the new DbConnectionInternal.</returns>
DbConnectionInternal ReplaceConnection(DbConnection owningObject, SqlConnectionOptions userOptions, DbConnectionInternal oldConnection);
DbConnectionInternal ReplaceConnection(DbConnection owningObject, DbConnectionInternal oldConnection);

/// <summary>
/// Returns an internal connection to the pool.
Expand Down
Loading
Loading