From e234159e878e47ece3c846a99d0048a50b098e20 Mon Sep 17 00:00:00 2001 From: dev02 Date: Fri, 22 Sep 2023 18:38:54 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=8C=E7=AB=AF]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=A7=A3=E6=9E=90mssql=20connect=20string=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Quartz/Jobs/ArchiveElectricMeterDayJob.cs | 2 +- Repository/BackendRepository/Implement/BackendRepository.cs | 5 +++++ Repository/BackendRepository/Interface/IBackendRepository.cs | 2 ++ Repository/Helper/DatabaseHelper.cs | 5 +++-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs index fbc75f5..350131e 100644 --- a/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs +++ b/BackendWorkerService/Quartz/Jobs/ArchiveElectricMeterDayJob.cs @@ -134,7 +134,6 @@ namespace BackendWorkerService.Quartz.Jobs #endregion 取得obix 設定 var now = DateTime.Now; - #region 天歸檔 if (await task_Detail.GetNeedWorkTask("ArchiveElectricMeterDayJob", "Day")) { @@ -630,6 +629,7 @@ namespace BackendWorkerService.Quartz.Jobs await task_Detail.WorkFail("ArchiveElectricMeterDayJob", "Day", exception.ToString()); logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【任務失敗】"); logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【任務失敗】[Exception]:{0}", exception.ToString()); + logger.LogError(await backgroundServiceMsSqlRepository.GetDbAllString()); } finally { diff --git a/Repository/BackendRepository/Implement/BackendRepository.cs b/Repository/BackendRepository/Implement/BackendRepository.cs index 3fefdab..88c05b4 100644 --- a/Repository/BackendRepository/Implement/BackendRepository.cs +++ b/Repository/BackendRepository/Implement/BackendRepository.cs @@ -136,5 +136,10 @@ namespace Repository.BackendRepository.Implement } } } + + public async Task GetDbAllString() + { + return "DBNAme:" + GetDbConnection().ConnectionString + " " + GetDbConnection().Database; + } } } diff --git a/Repository/BackendRepository/Interface/IBackendRepository.cs b/Repository/BackendRepository/Interface/IBackendRepository.cs index 2b91733..c241609 100644 --- a/Repository/BackendRepository/Interface/IBackendRepository.cs +++ b/Repository/BackendRepository/Interface/IBackendRepository.cs @@ -30,5 +30,7 @@ namespace Repository.BackendRepository.Interface /// /// Task ManualInsertFileBackgroundServiceTask(string building_ip, string building_guid, string target_table, List fileInfos); + + Task GetDbAllString(); } } diff --git a/Repository/Helper/DatabaseHelper.cs b/Repository/Helper/DatabaseHelper.cs index 0ffe0df..5120e14 100644 --- a/Repository/Helper/DatabaseHelper.cs +++ b/Repository/Helper/DatabaseHelper.cs @@ -44,9 +44,10 @@ namespace Repository.Helper var databaseStr = ed.AESDecrypt(_msSqlDBConfig.Database); var rootStr = ed.AESDecrypt(_msSqlDBConfig.Root); var passwordStr = ed.AESDecrypt(_msSqlDBConfig.Password); - var portStr = ed.AESDecrypt(_msSqlDBConfig.Port); + var portStr = !string.IsNullOrEmpty(_msSqlDBConfig.Port) ? ed.AESDecrypt(_msSqlDBConfig.Port) : string.Empty; - var connStr = $"data source={serverStr},{portStr};initial catalog={databaseStr};User ID={rootStr};Password={passwordStr}"; + string source = !string.IsNullOrEmpty(portStr) ? string.Join(",", serverStr, portStr) : serverStr; + var connStr = $"data source={source};initial catalog={databaseStr};User ID={rootStr};Password={passwordStr}"; //var conn = new SqlConnection(connStr); return connStr; }