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
+26 -7
View File
@@ -1,9 +1,11 @@
namespace BLL
{
using Model;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.Data.Linq;
using System.Globalization;
/// <summary>
/// 通用方法类。
@@ -13,12 +15,12 @@ namespace BLL
/// <summary>
/// 维护一个DB集合
/// </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>
/// 维护一个DB集合
/// </summary>
public static System.Collections.Generic.Dictionary<int, Model.SGGLDB> DBList
public static ConcurrentDictionary<int, Model.SGGLDB> DBList
{
get
{
@@ -125,12 +127,29 @@ namespace BLL
{
get
{
if (!DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId))
try
{
DBList.Add(System.Threading.Thread.CurrentThread.ManagedThreadId, new Model.SGGLDB(connString));
}
if (!DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId))
{
DBList.TryAdd(System.Threading.Thread.CurrentThread.ManagedThreadId, new SGGLDB(connString));
}
return DBList[System.Threading.Thread.CurrentThread.ManagedThreadId];
//DBList[System.Threading.Thread.CurrentThread.ManagedThreadId].CommandTimeout = 120;
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;
}
}
}
+3 -1
View File
@@ -165,7 +165,9 @@ namespace FineUIPro.Web
{
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();
}
}