public void BackConnection(PDBConnection conn, bool isErr) { if (!isErr && conn.IsValid()) { lock (this) { connList_.Add(conn); } } else { conn.Dispose(); Interlocked.Decrement(ref curConnCnt_); } connEvent_.Set(); }
public PDBConnection GetConnection() { do { lock (this) { while (connList_.Count > 0) { int idx = connList_.Count - 1; PDBConnection tmpConn = connList_[idx]; connList_.RemoveAt(idx); if (tmpConn.IsValid()) { return(tmpConn); } else { tmpConn.Dispose(); Interlocked.Decrement(ref curConnCnt_); connEvent_.Set(); } } if (curConnCnt_ < maxConnCnt_) { PDBConnection conn = new PDBConnection(connStr_); conn.Open(); Interlocked.Increment(ref curConnCnt_); return(conn); } else { connEvent_.Reset(); } } connEvent_.WaitOne(); } while (true); }
/// <summary> /// Open database with connectstring /// </summary> public void Open() { if (conn != null && conn.IsValid() == true) { ; } conn = new PDBConnection(ConnectString); conn.Open(); }