Skip to content

Commit 4a36399

Browse files
authored
Remove extra connection options parameters (#4261)
1 parent 95d212a commit 4a36399

12 files changed

Lines changed: 186 additions & 165 deletions

File tree

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ protected internal override Task<DataTable> GetSchemaAsync(
6262
internal override bool TryOpenConnection(
6363
DbConnection outerConnection,
6464
SqlConnectionFactory connectionFactory,
65-
TaskCompletionSource<DbConnectionInternal> retry,
66-
SqlConnectionOptions userOptions) =>
67-
TryOpenConnectionInternal(outerConnection, connectionFactory, retry, userOptions);
65+
TaskCompletionSource<DbConnectionInternal> retry) =>
66+
TryOpenConnectionInternal(outerConnection, connectionFactory, retry);
6867

6968
/// <inheritdoc/>
7069
internal override void ResetConnection() => throw ADP.ClosedConnectionError();
@@ -79,8 +78,7 @@ protected DbConnectionBusy(ConnectionState state) : base(state, true, false)
7978
internal override bool TryOpenConnection(
8079
DbConnection outerConnection,
8180
SqlConnectionFactory connectionFactory,
82-
TaskCompletionSource<DbConnectionInternal> retry,
83-
SqlConnectionOptions userOptions)
81+
TaskCompletionSource<DbConnectionInternal> retry)
8482
=> throw ADP.ConnectionAlreadyOpen(State);
8583
}
8684

@@ -121,15 +119,13 @@ internal override void CloseConnection(DbConnection owningObject, SqlConnectionF
121119
internal override bool TryReplaceConnection(
122120
DbConnection outerConnection,
123121
SqlConnectionFactory connectionFactory,
124-
TaskCompletionSource<DbConnectionInternal> retry,
125-
SqlConnectionOptions userOptions) =>
126-
TryOpenConnection(outerConnection, connectionFactory, retry, userOptions);
122+
TaskCompletionSource<DbConnectionInternal> retry) =>
123+
TryOpenConnection(outerConnection, connectionFactory, retry);
127124

128125
internal override bool TryOpenConnection(
129126
DbConnection outerConnection,
130127
SqlConnectionFactory connectionFactory,
131-
TaskCompletionSource<DbConnectionInternal> retry,
132-
SqlConnectionOptions userOptions)
128+
TaskCompletionSource<DbConnectionInternal> retry)
133129
{
134130
if (retry == null || !retry.Task.IsCompleted)
135131
{
@@ -177,8 +173,7 @@ private DbConnectionClosedPreviouslyOpened() : base(ConnectionState.Closed, true
177173
internal override bool TryReplaceConnection(
178174
DbConnection outerConnection,
179175
SqlConnectionFactory connectionFactory,
180-
TaskCompletionSource<DbConnectionInternal> retry,
181-
SqlConnectionOptions userOptions) =>
182-
TryOpenConnection(outerConnection, connectionFactory, retry, userOptions);
176+
TaskCompletionSource<DbConnectionInternal> retry) =>
177+
TryOpenConnection(outerConnection, connectionFactory, retry);
183178
}
184179
}

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ internal void MakePooledConnection(IDbConnectionPool connectionPool)
688688

689689
internal virtual void OpenConnection(DbConnection outerConnection, SqlConnectionFactory connectionFactory)
690690
{
691-
if (!TryOpenConnection(outerConnection, connectionFactory, null, null))
691+
if (!TryOpenConnection(outerConnection, connectionFactory, null))
692692
{
693693
throw ADP.InternalError(ADP.InternalErrorCode.SynchronousConnectReturnedPending);
694694
}
@@ -800,17 +800,15 @@ internal void SetInStasis()
800800
internal virtual bool TryOpenConnection(
801801
DbConnection outerConnection,
802802
SqlConnectionFactory connectionFactory,
803-
TaskCompletionSource<DbConnectionInternal> retry,
804-
SqlConnectionOptions userOptions)
803+
TaskCompletionSource<DbConnectionInternal> retry)
805804
{
806805
throw ADP.ConnectionAlreadyOpen(State);
807806
}
808807

809808
internal virtual bool TryReplaceConnection(
810809
DbConnection outerConnection,
811810
SqlConnectionFactory connectionFactory,
812-
TaskCompletionSource<DbConnectionInternal> retry,
813-
SqlConnectionOptions userOptions)
811+
TaskCompletionSource<DbConnectionInternal> retry)
814812
{
815813
throw ADP.MethodNotImplemented();
816814
}
@@ -912,8 +910,7 @@ protected virtual void ReleaseAdditionalLocksForClose(bool lockToken)
912910
protected bool TryOpenConnectionInternal(
913911
DbConnection outerConnection,
914912
SqlConnectionFactory connectionFactory,
915-
TaskCompletionSource<DbConnectionInternal> retry,
916-
SqlConnectionOptions userOptions)
913+
TaskCompletionSource<DbConnectionInternal> retry)
917914
{
918915
// ?->Connecting: prevent set_ConnectionString during Open
919916
if (connectionFactory.SetInnerConnectionFrom(outerConnection, DbConnectionClosedConnecting.SingletonInstance, this))
@@ -922,7 +919,7 @@ protected bool TryOpenConnectionInternal(
922919
try
923920
{
924921
connectionFactory.PermissionDemand(outerConnection);
925-
if (!connectionFactory.TryGetConnection(outerConnection, retry, userOptions, this, out openConnection))
922+
if (!connectionFactory.TryGetConnection(outerConnection, retry, this, out openConnection))
926923
{
927924
return false;
928925
}

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/SqlConnectionInternal.cs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,6 @@ internal class SqlConnectionInternal : DbConnectionInternal, IDisposable
312312
/// - Although the new password is generally not used it must be passed to the ctor. The
313313
/// new Login7 packet will always write out the new password (or a length of zero and no
314314
/// bytes if not present).
315-
/// - userConnectionOptions may be different to connectionOptions if the connection string
316-
/// has been expanded (see SqlConnectionOptions.Expand)
317315
/// </remarks>
318316
// @TODO: We really really need simplify what we pass into this. All these optional parameters need to go!
319317
internal SqlConnectionInternal(
@@ -324,7 +322,6 @@ internal SqlConnectionInternal(
324322
string newPassword,
325323
SecureString newSecurePassword,
326324
bool redirectedUserInstance,
327-
SqlConnectionOptions userConnectionOptions = null,
328325
SessionData reconnectSessionData = null,
329326
bool applyTransientFaultHandling = false,
330327
string accessToken = null,
@@ -341,29 +338,6 @@ internal SqlConnectionInternal(
341338
{
342339
reconnectSessionData._debugReconnectDataApplied = true;
343340
}
344-
345-
#if NETFRAMEWORK
346-
try
347-
{
348-
// use this to help validate this object is only created after the following
349-
// permission has been previously demanded in the current codepath
350-
if (userConnectionOptions != null)
351-
{
352-
// As mentioned above, userConnectionOptions may be different to
353-
// connectionOptions, so we need to demand on the correct connection string
354-
userConnectionOptions.DemandPermission();
355-
}
356-
else
357-
{
358-
connectionOptions.DemandPermission();
359-
}
360-
}
361-
catch (SecurityException)
362-
{
363-
Debug.Assert(false, "unexpected SecurityException for current codepath");
364-
throw;
365-
}
366-
#endif
367341
#endif
368342

369343
Debug.Assert(reconnectSessionData == null || connectionOptions.ConnectRetryCount > 0,
@@ -1970,10 +1944,9 @@ internal void OnLoginAck(SqlLoginAck rec)
19701944
internal override bool TryReplaceConnection(
19711945
DbConnection outerConnection,
19721946
SqlConnectionFactory connectionFactory,
1973-
TaskCompletionSource<DbConnectionInternal> retry,
1974-
SqlConnectionOptions userOptions)
1947+
TaskCompletionSource<DbConnectionInternal> retry)
19751948
{
1976-
return TryOpenConnectionInternal(outerConnection, connectionFactory, retry, userOptions);
1949+
return TryOpenConnectionInternal(outerConnection, connectionFactory, retry);
19771950
}
19781951

19791952
internal void ValidateConnectionForExecute(SqlCommand command)

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/ChannelDbConnectionPool.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ public void PutObjectFromTransactedPool(DbConnectionInternal connection)
224224
/// <inheritdoc />
225225
public DbConnectionInternal ReplaceConnection(
226226
DbConnection owningObject,
227-
SqlConnectionOptions userOptions,
228227
DbConnectionInternal oldConnection)
229228
{
230229
throw new NotImplementedException();
@@ -282,7 +281,6 @@ public void TransactionEnded(Transaction transaction, DbConnectionInternal trans
282281
public bool TryGetConnection(
283282
DbConnection owningObject,
284283
TaskCompletionSource<DbConnectionInternal>? taskCompletionSource,
285-
SqlConnectionOptions userOptions,
286284
out DbConnectionInternal? connection)
287285
{
288286
var timeout = TimeSpan.FromSeconds(owningObject.ConnectionTimeout);
@@ -292,7 +290,6 @@ public bool TryGetConnection(
292290
{
293291
var task = GetInternalConnection(
294292
owningObject,
295-
userOptions,
296293
async: false,
297294
timeout);
298295

@@ -340,7 +337,6 @@ public bool TryGetConnection(
340337
{
341338
connection = await GetInternalConnection(
342339
owningObject,
343-
userOptions,
344340
async: true,
345341
timeout
346342
).ConfigureAwait(false);
@@ -375,15 +371,13 @@ public bool TryGetConnection(
375371
/// Opens a new internal connection to the database.
376372
/// </summary>
377373
/// <param name="owningConnection">The owning connection.</param>
378-
/// <param name="userOptions">The options for the connection.</param>
379374
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
380375
/// <returns>A task representing the asynchronous operation, with a result of the new internal connection.</returns>
381376
/// <exception cref="OperationCanceledException">
382377
/// Thrown when the cancellation token is cancelled before the connection operation completes.
383378
/// </exception>
384379
private DbConnectionInternal? OpenNewInternalConnection(
385380
DbConnection? owningConnection,
386-
SqlConnectionOptions userOptions,
387381
CancellationToken cancellationToken)
388382
{
389383
cancellationToken.ThrowIfCancellationRequested();
@@ -405,8 +399,7 @@ public bool TryGetConnection(
405399
// when this support is added to DbConnectionInternal.
406400
var connection = ConnectionFactory.CreatePooledConnection(
407401
owningConnection,
408-
this,
409-
userOptions);
402+
this);
410403

411404
if (connection is not null)
412405
{
@@ -498,7 +491,6 @@ private void RemoveConnection(DbConnectionInternal connection)
498491
/// Gets an internal connection from the pool, either by retrieving an idle connection or opening a new one.
499492
/// </summary>
500493
/// <param name="owningConnection">The DbConnection that will own this internal connection</param>
501-
/// <param name="userOptions">The user options to set on the internal connection</param>
502494
/// <param name="async">A boolean indicating whether the operation should be asynchronous.</param>
503495
/// <param name="timeout">The timeout for the operation.</param>
504496
/// <returns>Returns a DbConnectionInternal that is retrieved from the pool.</returns>
@@ -512,7 +504,6 @@ private void RemoveConnection(DbConnectionInternal connection)
512504
/// </exception>
513505
private async Task<DbConnectionInternal> GetInternalConnection(
514506
DbConnection owningConnection,
515-
SqlConnectionOptions userOptions,
516507
bool async,
517508
TimeSpan timeout)
518509
{
@@ -533,7 +524,6 @@ private async Task<DbConnectionInternal> GetInternalConnection(
533524
// If we didn't find an idle connection, try to open a new one.
534525
connection ??= OpenNewInternalConnection(
535526
owningConnection,
536-
userOptions,
537527
cancellationToken);
538528

539529
// If we're at max capacity and couldn't open a connection. Block on the idle channel with a

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/IDbConnectionPool.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,17 @@ internal interface IDbConnectionPool
119119
/// <param name="owningObject">The SqlConnection that will own this internal connection.</param>
120120
/// <param name="taskCompletionSource">Used when calling this method in an async context.
121121
/// The internal connection will be set on completion source rather than passed out via the out parameter.</param>
122-
/// <param name="userOptions">The user options to use if a new connection must be opened.</param>
123122
/// <param name="connection">The retrieved connection will be passed out via this parameter.</param>
124123
/// <returns>True if a connection was set in the out parameter, otherwise returns false.</returns>
125-
bool TryGetConnection(DbConnection owningObject, TaskCompletionSource<DbConnectionInternal>? taskCompletionSource, SqlConnectionOptions userOptions, out DbConnectionInternal? connection);
124+
bool TryGetConnection(DbConnection owningObject, TaskCompletionSource<DbConnectionInternal>? taskCompletionSource, out DbConnectionInternal? connection);
126125

127126
/// <summary>
128127
/// Replaces the internal connection currently associated with owningObject with a new internal connection from the pool.
129128
/// </summary>
130-
/// <param name="owningObject">The connection whos internal connection should be replaced.</param>
131-
/// <param name="userOptions">The user options to use if a new connection must be opened.</param>
129+
/// <param name="owningObject">The connection whose internal connection should be replaced.</param>
132130
/// <param name="oldConnection">The internal connection currently associated with the owning object.</param>
133131
/// <returns>A reference to the new DbConnectionInternal.</returns>
134-
DbConnectionInternal ReplaceConnection(DbConnection owningObject, SqlConnectionOptions userOptions, DbConnectionInternal oldConnection);
132+
DbConnectionInternal ReplaceConnection(DbConnection owningObject, DbConnectionInternal oldConnection);
135133

136134
/// <summary>
137135
/// Returns an internal connection to the pool.

0 commit comments

Comments
 (0)