From 09d23bcb788f1f38072643ece779e0ee258fc0a5 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Fri, 17 Nov 2023 12:57:23 -0600 Subject: [PATCH] Don't dispose database context for server processes --- LANCommander/Program.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/LANCommander/Program.cs b/LANCommander/Program.cs index 72aa0f1..5e92bfb 100644 --- a/LANCommander/Program.cs +++ b/LANCommander/Program.cs @@ -228,17 +228,16 @@ namespace LANCommander // Migrate Logger.Debug("Migrating database if required"); await using var scope = app.Services.CreateAsyncScope(); - using (var db = scope.ServiceProvider.GetService()) + using var db = scope.ServiceProvider.GetService(); + + if ((await db.Database.GetPendingMigrationsAsync()).Any()) { - if ((await db.Database.GetPendingMigrationsAsync()).Any()) - { - var dataSource = new SqliteConnectionStringBuilder(settings.DatabaseConnectionString).DataSource; + var dataSource = new SqliteConnectionStringBuilder(settings.DatabaseConnectionString).DataSource; - if (File.Exists(dataSource)) - File.Copy(dataSource, Path.Combine("Backups", $"LANCommander.db.{DateTime.Now.ToString("dd-MM-yyyy-HH.mm.ss.bak")}")); + if (File.Exists(dataSource)) + File.Copy(dataSource, Path.Combine("Backups", $"LANCommander.db.{DateTime.Now.ToString("dd-MM-yyyy-HH.mm.ss.bak")}")); - await db.Database.MigrateAsync(); - } + await db.Database.MigrateAsync(); } // Autostart any server processes