public void Dispose() { if (CurrentDbConnection != null) { if (CurrentDbConnection.State != ConnectionState.Closed) { if (CurrentTransaction != null) { CurrentTransaction.Commit(); } CurrentDbConnection.Close(); } CurrentDbConnection.Dispose(); CurrentTransaction = null; } }
/// <summary> /// 执行查询语句,返回SqlDataReader ( 注意:使用后一定要对SqlDataReader进行Close ) /// </summary> /// <param name="strSql">查询语句</param> /// <returns>SqlDataReader</returns> public IDataReader ExecuteReader(string strSql) { MySqlCommand command = new MySqlCommand(strSql); PrepareCommand(command, CurrentDbConnection, CurrentTransaction, CommandType.Text, null); MySqlDataReader dr = null; try { dr = command.ExecuteReader(CommandBehavior.Default); } catch (Exception ex) { CurrentDbConnection.Close(); CurrentDbConnection.Dispose(); throw ex; } return(dr); }
/// <summary> /// 执行查询语句,返回SqlDataReader ( 注意:使用后一定要对SqlDataReader进行Close ) /// </summary> /// <param name="strSql">SQL语句</param> /// <param name="cmdParms">查询参数</param> /// <returns>SqlDataReader</returns> public IDataReader ExecuteReader(string strSql, params DbParameter[] cmdParms) { OracleCommand command = new OracleCommand(strSql); PrepareCommand(command, CurrentDbConnection, CurrentTransaction, CommandType.Text, cmdParms); OracleDataReader dr = null; try { dr = command.ExecuteReader(CommandBehavior.Default); } catch (Exception ex) { CurrentDbConnection.Close(); CurrentDbConnection.Dispose(); throw ex; } finally { command.Parameters.Clear(); } return(dr); }