[後端] 修改解析mssql connect string問題

This commit is contained in:
dev02 2023-09-22 18:38:54 +08:00
parent 3b12a644de
commit e234159e87
4 changed files with 11 additions and 3 deletions

View File

@ -134,7 +134,6 @@ namespace BackendWorkerService.Quartz.Jobs
#endregion obix #endregion obix
var now = DateTime.Now; var now = DateTime.Now;
#region #region
if (await task_Detail.GetNeedWorkTask("ArchiveElectricMeterDayJob", "Day")) if (await task_Detail.GetNeedWorkTask("ArchiveElectricMeterDayJob", "Day"))
{ {
@ -630,6 +629,7 @@ namespace BackendWorkerService.Quartz.Jobs
await task_Detail.WorkFail("ArchiveElectricMeterDayJob", "Day", exception.ToString()); await task_Detail.WorkFail("ArchiveElectricMeterDayJob", "Day", exception.ToString());
logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【任務失敗】"); logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【任務失敗】");
logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【任務失敗】[Exception]{0}", exception.ToString()); logger.LogError("【ArchiveElectricMeterDayJob】【天歸檔】【任務失敗】[Exception]{0}", exception.ToString());
logger.LogError(await backgroundServiceMsSqlRepository.GetDbAllString());
} }
finally finally
{ {

View File

@ -136,5 +136,10 @@ namespace Repository.BackendRepository.Implement
} }
} }
} }
public async Task<string> GetDbAllString()
{
return "DBNAme:" + GetDbConnection().ConnectionString + " " + GetDbConnection().Database;
}
} }
} }

View File

@ -30,5 +30,7 @@ namespace Repository.BackendRepository.Interface
/// <param name="fileInfos"></param> /// <param name="fileInfos"></param>
/// <returns></returns> /// <returns></returns>
Task ManualInsertFileBackgroundServiceTask(string building_ip, string building_guid, string target_table, List<Models.FileInfo> fileInfos); Task ManualInsertFileBackgroundServiceTask(string building_ip, string building_guid, string target_table, List<Models.FileInfo> fileInfos);
Task<string> GetDbAllString();
} }
} }

View File

@ -44,9 +44,10 @@ namespace Repository.Helper
var databaseStr = ed.AESDecrypt(_msSqlDBConfig.Database); var databaseStr = ed.AESDecrypt(_msSqlDBConfig.Database);
var rootStr = ed.AESDecrypt(_msSqlDBConfig.Root); var rootStr = ed.AESDecrypt(_msSqlDBConfig.Root);
var passwordStr = ed.AESDecrypt(_msSqlDBConfig.Password); 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); //var conn = new SqlConnection(connStr);
return connStr; return connStr;
} }