/// <summary> /// 向連接池歸還連接 /// </summary> /// <param name="db"></param> public void Return(OleExec db) { lock (this) { try { db.RollbackTrain(); } catch { } try { OleExecPoolItem item = Lend[db]; All.Add(item); Lend.Remove(db); } catch { //LockType = ""; //useLock = false; } finally { } } }
/// <summary> /// 借出一個連接 /// </summary> /// <returns></returns> public OleExec Borrow() { lock (this) { int sleepCount = 0; while (AutoLock || useLock) { sleepCount++; if ((sleepCount * 100) > PoolTimeOut * 1000) { throw new Exception("連接池借出等待超時!"); } System.Threading.Thread.Sleep(100); } useLock = true; LockTime = DateTime.Now; LockType = "Borrow"; OleExec ret = null; OleExecPoolItem Item = null; try { if (All.Count == 0 && Lend.Count < MaxPoolSize) { LockType = "Borrow CreateNewItem"; CreateNewItem(); } if (All.Count > 0) { Item = All[0]; LockType = "Borrow All.Remove(Item)"; All.Remove(Item); ret = Item.Data; Item.LendTime = DateTime.Now; LockType = "Borrow Lend.Add(ret, Item);"; Lend.Add(ret, Item); } else { throw new Exception("連接池超過最大配置,無法借出"); } } catch (Exception ee) { LockType = ""; LockTime = null; useLock = false; throw ee; } finally { LockType = ""; LockTime = null; useLock = false; } return(ret); } }
void CreateNewItem() { OleExecPoolItem Item = null; OleExec newOle = new OleExec(_ConnectionString, this); Item = new OleExecPoolItem(); Item.Data = newOle; Item.CreateTime = DateTime.Now; All.Add(Item); }
/// <summary> /// 向連接池歸還連接 /// </summary> /// <param name="db"></param> public void Return(OleExec db) { //int sleepCount = 0; while (AutoLock || useLock) { //sleepCount++; //if ((sleepCount * 100) > PoolTimeOut * 1000) //{ // throw new Exception("連接池借出等待超時!"); //} System.Threading.Thread.Sleep(100); } useLock = true; LockTime = DateTime.Now; LockType = "Return db.RollbackTrain();"; try { db.RollbackTrain(); } catch { } try { OleExecPoolItem item = Lend[db]; LockType = "Return All.Add(item);"; All.Add(item); LockType = "Return Lend.Remove(db);"; Lend.Remove(db); } catch { //LockType = ""; //useLock = false; } finally { LockType = ""; LockTime = null; useLock = false; } }
/// <summary> /// 借出一個連接 /// </summary> /// <returns></returns> public OleExec Borrow() { lock (this) { OleExec ret = null; OleExecPoolItem Item = null; try { if (All.Count == 0 && Lend.Count < MaxPoolSize) { CreateNewItem(); } if (All.Count > 0) { Item = All[0]; All.Remove(Item); ret = Item.Data; Item.LendTime = DateTime.Now; Lend.Add(ret, Item); } else { throw new Exception("連接池超過最大配置,無法借出"); } } catch (Exception ee) { throw ee; } finally { } return(ret); } }