public DbConnection GetConnection(object key, ConnectionLevel level) { lock (PoolLocker) { if (_ps != PoolState.Run) { throw new StateException();//服务状态错误 } if (useConns.Count == MaxConnectionFromPool) { throw new PoolFullException();//连接池已经饱和,不能提供连接 } if (useConns.ContainsKey(key)) { throw new KeyExecption();//一个key只能申请一个连接 } switch (level) { case ConnectionLevel.ReadOnly: return(GetConnectionByReadOnly(key)); case ConnectionLevel.High: return(GetConnectionByHigh(key)); case ConnectionLevel.None: return(GetConnectionByNone(key)); default: return(GetConnectionByBase(key)); } } }
public DbConnection GetConnection(object key, ConnectionLevel level, Connector conn) { try { if (conn == null) { return(null); } if (conn.DbConnection.State != ConnectionState.Closed) { return(null); } conn.Repeat(); useConns.Add(key, conn); if (level == ConnectionLevel.ReadOnly) { conn.CanAllocation = false; conn.IsRepeat = false; } } catch { throw new OccasionExecption(); } finally { UpdatePoolState(); } return(conn.DbConnection); }
public DbAgent(string name, string constr, bool state, ConnectionLevel level = ConnectionLevel.Single, int timeout = 30) { Name = name; SetConnectionString(constr); SetState(state); ConnectionLevel = level; RunTimeout = timeout; }