From 971e03ccbe5124d4761f56e71025453d1d4742bc Mon Sep 17 00:00:00 2001 From: 啊鑫 <t2856754968@163.com> Date: 星期三, 17 九月 2025 14:17:08 +0800 Subject: [PATCH] 111 --- util/DbHelperSQL.cs | 34 ++++++++++++++++++++-------------- 1 files changed, 20 insertions(+), 14 deletions(-) diff --git a/util/DbHelperSQL.cs b/util/DbHelperSQL.cs index 468dd88..4778134 100644 --- a/util/DbHelperSQL.cs +++ b/util/DbHelperSQL.cs @@ -2,7 +2,7 @@ using System.Data; using System.Data.SqlClient; -namespace Gs.Toolbox; +namespace NewPdaSqlServer.util; /// <summary> /// 鏁版嵁璁块棶绫� @@ -12,6 +12,24 @@ //鏁版嵁搴撹繛鎺ュ瓧绗︿覆(web.config鏉ラ厤缃�) public static readonly string strConn = getValueByKey("DataBaseConn"); + + + public static string getValueByKey(string key) + { + // 鍒涘缓閰嶇疆鏋勫缓鍣� + var builder = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true); + // 鏋勫缓閰嶇疆 + var configuration = builder.Build(); + // 淇閰嶇疆璺緞锛氬鏋滄槸DataBaseConn锛岄渶瑕佷粠AppSettings鑺傜偣璇诲彇 + if (key == "DataBaseConn") + { + return configuration["AppSettings:DataBaseConn"]; + } + return configuration[key]; + } #region 鍏敤鏂规硶 @@ -571,6 +589,7 @@ else str = str + "|" + command.Parameters[a].Value; } + return str; } @@ -672,17 +691,4 @@ } #endregion - - - public static string getValueByKey(string key) - { - // 鍒涘缓閰嶇疆鏋勫缓鍣� - var builder = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json", true, true); - // 鏋勫缓閰嶇疆 - var configuration = builder.Build(); - return configuration[key]; - } - } \ No newline at end of file -- Gitblit v1.9.3