Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SqlConnectionOverrides for OpenAsync() API #2433

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -1974,9 +1974,6 @@ private bool TryOpen(TaskCompletionSource<DbConnectionInternal> retry, SqlConnec
}
// does not require GC.KeepAlive(this) because of ReRegisterForFinalize below.

// Set future transient fault handling based on connection options
_applyTransientFaultHandling = connectionOptions != null && connectionOptions.ConnectRetryCount > 0;

var tdsInnerConnection = (SqlInternalConnectionTds)InnerConnection;

Debug.Assert(tdsInnerConnection.Parser != null, "Where's the parser?");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ override protected DbConnectionInternal CreateConnection(DbConnectionOptions opt
// NOTE: Retrieve <UserInstanceName> here. This user instance name will be used below to connect to the Sql Express User Instance.
instanceName = sseConnection.InstanceName;

// Set future transient fault handling based on connection options
sqlOwningConnection._applyTransientFaultHandling = opt != null && opt.ConnectRetryCount > 0;
Copy link
Member Author

@cheenamalhotra cheenamalhotra Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This had to be moved here as in async flow, connection attempt happens on another thread and the value gets reset very quickly to be captured again when retry is attempted. So fail fast wasn't really working. This change makes sure the value gets reset after the login flow is complete.

cc @David-Engel for second set of eyes


if (!instanceName.StartsWith("\\\\.\\", StringComparison.Ordinal))
{
throw SQL.NonLocalSSEInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2145,9 +2145,6 @@ private bool TryOpen(TaskCompletionSource<DbConnectionInternal> retry, SqlConnec
result = TryOpenInner(retry);
}

// Set future transient fault handling based on connection options
_applyTransientFaultHandling = connectionOptions != null && connectionOptions.ConnectRetryCount > 0;

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ override protected DbConnectionInternal CreateConnection(DbConnectionOptions opt
// NOTE: Retrieve <UserInstanceName> here. This user instance name will be used below to connect to the Sql Express User Instance.
instanceName = sseConnection.InstanceName;

// Set future transient fault handling based on connection options
sqlOwningConnection._applyTransientFaultHandling = opt != null && opt.ConnectRetryCount > 0;

if (!instanceName.StartsWith("\\\\.\\", StringComparison.Ordinal))
{
throw SQL.NonLocalSSEInstance();
Expand Down
Loading