diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerConnection.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerConnection.cs index 1383888a3ad..d4c5693d01f 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerConnection.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerConnection.cs @@ -38,7 +38,6 @@ public SqlServerConnection(RelationalConnectionDependencies dependencies) /// protected override void OpenDbConnection(bool errorsExpected) { - // Note: Not needed for the Async overload: see https://github.com/dotnet/SqlClient/issues/615 if (errorsExpected && DbConnection is SqlConnection sqlConnection) { @@ -50,6 +49,25 @@ protected override void OpenDbConnection(bool errorsExpected) } } + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + protected override Task OpenDbConnectionAsync(bool errorsExpected, CancellationToken cancellationToken) + { + if (errorsExpected + && DbConnection is SqlConnection sqlConnection) + { + return sqlConnection.OpenAsync(SqlConnectionOverrides.OpenWithoutRetry, cancellationToken); + } + else + { + return DbConnection.OpenAsync(cancellationToken); + } + } + /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in