From 4ab8f8cc2548501fdd1072485f5be36c3ca04752 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Thu, 14 Aug 2025 15:57:50 -0400 Subject: [PATCH] improve error handling for the scenario where a connection string does not exist in appsettings.json for a tenant --- Oqtane.Server/Infrastructure/DatabaseManager.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Oqtane.Server/Infrastructure/DatabaseManager.cs b/Oqtane.Server/Infrastructure/DatabaseManager.cs index af54c35f..bfb3be45 100644 --- a/Oqtane.Server/Infrastructure/DatabaseManager.cs +++ b/Oqtane.Server/Infrastructure/DatabaseManager.cs @@ -392,11 +392,20 @@ namespace Oqtane.Infrastructure tenant.DBConnectionString = MigrateConnectionString(db, tenant); try { - using (var tenantDbContext = new TenantDBContext(DBContextDependencies)) + var connectionString = _configManager.GetSetting($"{SettingKeys.ConnectionStringsSection}:{tenant.DBConnectionString}", ""); + if (!string.IsNullOrEmpty(connectionString)) { - AddEFMigrationsHistory(sql, _configManager.GetSetting($"{SettingKeys.ConnectionStringsSection}:{tenant.DBConnectionString}", ""), tenant.DBType, tenant.Version, false); - // push latest model into database - tenantDbContext.Database.Migrate(); + using (var tenantDbContext = new TenantDBContext(DBContextDependencies)) + { + AddEFMigrationsHistory(sql, connectionString, tenant.DBType, tenant.Version, false); + // push latest model into database + tenantDbContext.Database.Migrate(); + } + } + else + { + result.Message = "A Connection String Named " + tenant.DBConnectionString + " Does Not Exist For Tenant " + tenant.Name + " In The ConnectionStrings Section Of Appsettings.json"; + _filelogger.LogError(Utilities.LogMessage(this, result.Message)); } } catch (Exception ex)