Skip to content

Commit

Permalink
SonarQube worthless nagging.
Browse files Browse the repository at this point in the history
  • Loading branch information
jahav committed Oct 3, 2024
1 parent 2e72ada commit 83f3d2b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
13 changes: 8 additions & 5 deletions sample/WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddDbContext<AppDbContext>(options =>
builder.Services.AddDbContext<WebApi.AppDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("AppDb"))
);

var app = builder.Build();

app.MapGet("/db-name", async (AppDbContext dbContext) =>
app.MapGet("/db-name", async (WebApi.AppDbContext dbContext) =>
{
// Wait a little before and after, so we know two requests are handled at the same time.
await Task.Delay(2500);
Expand All @@ -18,9 +18,12 @@
return Results.Text(dbName);
});

app.Run();
await app.RunAsync();

public partial class Program;

public class AppDbContext(DbContextOptions<AppDbContext> options)
: DbContext(options);
namespace WebApi
{
public class AppDbContext(DbContextOptions<AppDbContext> options)
: DbContext(options);
}
8 changes: 6 additions & 2 deletions src/DataIsland.SqlServer/SqlDatabaseTenantFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task<SqlDatabaseTenant> AddTenantAsync(SqlServerComponent component

// Because connection string of component doesn't differ, it will be pooled.
using var connection = new SqlConnection(component.ConnectionString);
connection.Open();
await connection.OpenAsync();

var command = connection.CreateCommand();
if (!spec.HasDataSource)
Expand Down Expand Up @@ -61,12 +61,16 @@ public async Task<SqlDatabaseTenant> AddTenantAsync(SqlServerComponent component
command.CommandText = cmd.ToString();
}

command.ExecuteNonQuery();
await command.ExecuteNonQueryAsync();

if (spec.MaxDop is { } maxDop)
await SetMaxDopAsync(connection, tenantDbName, maxDop);

#if NET6_0_OR_GREATER
await connection.CloseAsync();
#else
connection.Close();
#endif

var tenantConnectionString = new SqlConnectionStringBuilder(component.ConnectionString)
{
Expand Down
8 changes: 8 additions & 0 deletions src/DataIsland.SqlServer/SqlServerSpecChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ internal static class SqlServerSpecChecker
var command = connection.CreateCommand();
command.CommandText = "SELECT SERVERPROPERTY('Collation')";
var collation = (string?)await command.ExecuteScalarAsync();
#if NET6_0_OR_GREATER
await connection.CloseAsync();
#else
connection.Close();
#endif
if (collation != componentSpec.Collation)
return $"Unable to find a server with collation {componentSpec.Collation}.";
}
Expand All @@ -38,7 +42,11 @@ [name] nvarchar(35),
""";
var clrConfigValue = (int?)await command.ExecuteScalarAsync();
var actualClrEnabled = clrConfigValue is not null && clrConfigValue.Value != 0;
#if NET6_0_OR_GREATER
await connection.CloseAsync();
#else
connection.Close();
#endif
if (actualClrEnabled != desiredClrEnabled)
return $"Unable to find a server with clr {(desiredClrEnabled ? "enabled" : "disabled")}.";
}
Expand Down

0 comments on commit 83f3d2b

Please sign in to comment.