diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerDatabaseCreator.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerDatabaseCreator.cs index 7fdfbd28cc1..7cc59797434 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerDatabaseCreator.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerDatabaseCreator.cs @@ -185,12 +185,18 @@ private bool Exists(bool retryOnNotExists) { try { - using (new TransactionScope(TransactionScopeOption.Suppress)) - { - _connection.Open(errorsExpected: true); - _connection.Close(); - } - + using var _ = new TransactionScope(TransactionScopeOption.Suppress); + _connection.Open(errorsExpected: true); + + _rawSqlCommandBuilder + .Build("SELECT 1") + .ExecuteNonQuery(new RelationalCommandParameterObject( + _connection, + null, + Dependencies.CurrentContext.Context, + Dependencies.CommandLogger)); + + _connection.Close(); return true; } catch (SqlException e) @@ -229,13 +235,19 @@ private Task ExistsAsync(bool retryOnNotExists, CancellationToken cancella { try { - using (new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled)) - { - await _connection.OpenAsync(ct, errorsExpected: true); - - await _connection.CloseAsync(); - } - + using var _ = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled); + await _connection.OpenAsync(ct, errorsExpected: true); + + await _rawSqlCommandBuilder + .Build("SELECT 1") + .ExecuteNonQueryAsync(new RelationalCommandParameterObject( + _connection, + null, + Dependencies.CurrentContext.Context, + Dependencies.CommandLogger), + ct); + + await _connection.CloseAsync(); return true; } catch (SqlException e)