/// <summary> /// 用指定类型创建连接 /// </summary> /// <param name="conn">连接字符串</param> /// <param name="cte">连接类型</param> /// <param name="dt">连接超时时间</param> /// <returns>返回创建的连接</returns> private ConnStruct CreateConnection(string conn, ConnTypeEnum cte) { DbConnection db = null; if (cte == ConnTypeEnum.Odbc) { db = new System.Data.Odbc.OdbcConnection(conn);//ODBC数据源连接 } else if (cte == ConnTypeEnum.OleDb) { db = new System.Data.OleDb.OleDbConnection(conn);//OLE DB数据连接,Access数据库 } else if (cte == ConnTypeEnum.SqlClient) { db = new System.Data.SqlClient.SqlConnection(conn);//SqlServer数据库连接 } else if (cte == ConnTypeEnum.MySqlClient) { db = new MySql.Data.MySqlClient.MySqlConnection(conn);//MySqlServer数据库连接 } else if (cte == ConnTypeEnum.OracleClient) { db = new System.Data.OracleClient.OracleConnection(conn);//Oracle数据库连接 } else if (cte == ConnTypeEnum.MsModelClient) { db = new System.Data.EntityClient.EntityConnection(conn);//Microsoft数据库连接 } ConnStruct cs = new ConnStruct(db, cte, DateTime.Now); cs.Open(); return(cs); }
/// <summary> /// 连接池中的连接 /// </summary> /// <param name="dbc">数据库连接</param> /// <param name="cte">连接类型</param> public ConnStruct(DbConnection dbc, ConnTypeEnum cte) { createTime = DateTime.Now; connect = dbc; connType = cte; obj = Guid.NewGuid(); repeatKeyList = new List <string>(); }
/// <summary> /// 初始化函数 /// </summary> protected void InitConnectionPool(string connectionString, ConnTypeEnum cte, int maxConnection, int minConnection, int seepConnection, int keepRealConnection) { if (cte == ConnTypeEnum.None) { throw new ConnTypeExecption();//参数不能是None } _ps = PoolState.UnInitialize; this._connString = connectionString; this._connType = cte; this._minConnection = minConnection; this._seepConnection = seepConnection; this._keepRealConnection = keepRealConnection; this._maxConnection = maxConnection; //连接状态检查线程 this.threadCheck = new Thread(new ThreadStart(checkThreadProcess)); this.threadCreate = new Thread(new ThreadStart(createThreadProcess)); }
/// <summary> /// 初始化函数 /// </summary> /// <param name="connectionString">数据库连接字符串</param> /// <param name="cte">数据库连接类型</param> /// <param name="maxConnection">最大连接数,最大可以创建的连接数目</param> /// <param name="minConnection">最小连接数</param> /// <param name="seepConnection">每次创建连接的连接数</param> /// <param name="keepConnection">保留连接数,当空闲连接不足该数值时,连接池将创建seepConnection个连接</param> /// <param name="keepRealConnection">当空闲的实际连接不足该值时创建连接,直到达到最大连接数</param> protected void InitConnectionPool(string connectionString, ConnTypeEnum cte, int maxConnection, int minConnection, int seepConnection, int keepConnection, int keepRealConnection) { if (cte == ConnTypeEnum.None) { throw new ConnTypeExecption();//参数不能是None } _ps = PoolState.UnInitialize; this._connString = connectionString; this._connType = cte; this._minConnection = minConnection; this._seepConnection = seepConnection; this._keepRealConnection = keepRealConnection; this._maxConnection = maxConnection; this.time = new System.Timers.Timer(500); this.time.Stop(); this.time.Elapsed += new System.Timers.ElapsedEventHandler(time_Elapsed); this.threadCreate = new Thread(new ThreadStart(createThreadProcess)); //启动服务 StartServices(); }
/// <summary> /// 初始化连接池 /// </summary> /// <param name="connectionString">数据库连接字符串</param> /// <param name="cte">数据库连接类型</param> /// <param name="maxConnection">最大连接数,最大可以创建的连接数目</param> /// <param name="minConnection">最小连接数</param> /// <param name="seepConnection">每次创建连接的连接数</param> /// <param name="keepConnection">保留连接数,当空闲连接不足该数值时,连接池将创建seepConnection个连接</param> /// <param name="keepRealConnection">当空闲的实际连接不足该值时创建连接,直到达到最大连接数</param> public ConnectionPool(string connectionString, ConnTypeEnum cte, int maxConnection, int minConnection, int seepConnection, int keepConnection, int keepRealConnection) { InitConnectionPool(connectionString, cte, maxConnection, minConnection, seepConnection, keepConnection, keepRealConnection); }
/// <summary> /// 初始化连接池 /// </summary> /// <param name="connectionString">数据库连接字符串</param> /// <param name="cte">数据库连接类型</param> /// <param name="maxConnection">最大连接数,最大可以创建的连接数目</param> /// <param name="minConnection">最小连接数</param> public ConnectionPool(string connectionString, ConnTypeEnum cte, int maxConnection, int minConnection) { InitConnectionPool(connectionString, cte, maxConnection, minConnection, 10, 5, 5); }
/// <summary> /// 初始化连接池 /// </summary> /// <param name="connectionString">数据库连接字符串</param> /// <param name="cte">数据库连接类型</param> public ConnectionPool(string connectionString, ConnTypeEnum cte) { InitConnectionPool(connectionString, cte, 200, 30, 10, 5, 5); }
/// <summary> /// 连接池中的连接 /// </summary> /// <param name="dbc">数据库连接</param> /// <param name="cte">连接类型</param> /// <param name="dt">连接创建时间</param> public ConnStruct(DbConnection dbc, ConnTypeEnum cte, DateTime dt) { createTime = dt; connect = dbc; connType = cte; }
/// <summary> /// 连接池中的连接 /// </summary> /// <param name="dbc">数据库连接</param> /// <param name="cte">连接类型</param> public ConnStruct(DbConnection dbc, ConnTypeEnum cte) { createTime = DateTime.Now; connect = dbc; connType = cte; }