Skip to content

Commit

Permalink
async delete
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyGaluzo committed Jun 16, 2024
1 parent 66d3da9 commit 4cfba86
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,18 @@ public async Task DeleteDatabase(string databaseName, CancellationToken cancella

try
{
DbSetupSemaphore.Wait();
await DbSetupSemaphore.WaitAsync(cancellationToken);
try
{
SqlConnection.ClearAllPools();
using var conn = _sqlConnectionBuilder.GetSqlConnection(_masterDatabaseName, null);
conn.Open();
using var cmd = new SqlCommand($"DROP DATABASE IF EXISTS {databaseName}", conn);
cmd.ExecuteNonQuery();
await Task.CompletedTask;

await using SqlConnection connection = await _sqlConnectionBuilder.GetSqlConnectionAsync(_masterDatabaseName, null, cancellationToken);
await connection.OpenAsync(cancellationToken);
await using SqlCommand command = connection.CreateCommand();
command.CommandTimeout = 15;
command.CommandText = $"DROP DATABASE IF EXISTS {databaseName}";
await command.ExecuteNonQueryAsync(cancellationToken);
await connection.CloseAsync();
}
finally
{
Expand Down

0 comments on commit 4cfba86

Please sign in to comment.