This commit is contained in:
2026-06-09 15:47:01 +08:00
parent 9b4db50bfe
commit 420b242006
2 changed files with 29 additions and 8 deletions
+23 -4
View File
@@ -1,9 +1,11 @@
namespace BLL namespace BLL
{ {
using Model;
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Data.Linq; using System.Data.Linq;
using System.Globalization;
/// <summary> /// <summary>
/// 通用方法类。 /// 通用方法类。
@@ -13,12 +15,12 @@ namespace BLL
/// <summary> /// <summary>
/// 维护一个DB集合 /// 维护一个DB集合
/// </summary> /// </summary>
private static Dictionary<int, Model.SGGLDB> dataBaseLinkList = new System.Collections.Generic.Dictionary<int, Model.SGGLDB>(); private static ConcurrentDictionary<int, Model.SGGLDB> dataBaseLinkList = new ConcurrentDictionary<int, Model.SGGLDB>();
/// <summary> /// <summary>
/// 维护一个DB集合 /// 维护一个DB集合
/// </summary> /// </summary>
public static System.Collections.Generic.Dictionary<int, Model.SGGLDB> DBList public static ConcurrentDictionary<int, Model.SGGLDB> DBList
{ {
get get
{ {
@@ -124,14 +126,31 @@ namespace BLL
public static Model.SGGLDB DB public static Model.SGGLDB DB
{ {
get get
{
try
{ {
if (!DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId)) if (!DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId))
{ {
DBList.Add(System.Threading.Thread.CurrentThread.ManagedThreadId, new Model.SGGLDB(connString)); DBList.TryAdd(System.Threading.Thread.CurrentThread.ManagedThreadId, new SGGLDB(connString));
} }
//DBList[System.Threading.Thread.CurrentThread.ManagedThreadId].CommandTimeout = 120;
return DBList[System.Threading.Thread.CurrentThread.ManagedThreadId]; return DBList[System.Threading.Thread.CurrentThread.ManagedThreadId];
} }
catch
{
var db = new SGGLDB(connString);
if (DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId))
{
DBList[System.Threading.Thread.CurrentThread.ManagedThreadId] = db;
}
else
{
DBList.TryAdd(System.Threading.Thread.CurrentThread.ManagedThreadId, db);
}
return db;
}
}
} }
/// <summary> /// <summary>
+3 -1
View File
@@ -165,7 +165,9 @@ namespace FineUIPro.Web
{ {
if (BLL.Funs.DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId)) if (BLL.Funs.DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId))
{ {
BLL.Funs.DBList.Remove(System.Threading.Thread.CurrentThread.ManagedThreadId); Model.SGGLDB outdb;
BLL.Funs.DBList.TryRemove(System.Threading.Thread.CurrentThread.ManagedThreadId, out outdb);
outdb.Dispose();
} }
} }