Esempio n. 1
0
 public void Dispose()
 {
     if (_connection != null)
     {
         _connection.Dispose();
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 关闭数据库连接
 /// </summary>
 public void Close()
 {
     if (Conn != null)
     {
         Conn.Close();
         Conn.Dispose();
     }
 }
Esempio n. 3
0
        private DataTable RunSQLReturnTable(string sql, System.Data.Common.DbConnection conn, string dsn, CommandType cmdType)
        {
            if (conn is System.Data.SqlClient.SqlConnection)
            {
                return(BP.DA.DBAccess.RunSQLReturnTable(sql, (System.Data.SqlClient.SqlConnection)conn, dsn, cmdType));
            }
            if (conn is System.Data.OleDb.OleDbConnection)
            {
                return(BP.DA.DBAccess.RunSQLReturnTable(sql, (System.Data.OleDb.OleDbConnection)conn, cmdType));
            }
            if (conn is System.Data.OracleClient.OracleConnection)
            {
                return(BP.DA.DBAccess.RunSQLReturnTable(sql, (System.Data.OracleClient.OracleConnection)conn, cmdType, dsn));
            }
            if (conn is MySqlConnection)
            {
                var mySqlConn = (MySqlConnection)conn;
                if (mySqlConn.State != ConnectionState.Open)
                {
                    mySqlConn.Open();
                }

                var ada = new MySqlDataAdapter(sql, mySqlConn);
                ada.SelectCommand.CommandType = CommandType.Text;


                try
                {
                    DataTable oratb = new DataTable("otb");
                    ada.Fill(oratb);
                    ada.Dispose();

                    conn.Close();
                    conn.Dispose();
                    return(oratb);
                }
                catch (Exception ex)
                {
                    ada.Dispose();
                    conn.Close();
                    throw new Exception("SQL=" + sql + " Exception=" + ex.Message);
                }
            }

            throw new Exception("没有涉及到的连接测试类型...");
            return(null);
        }
 /// <summary>
 /// Cleanup.
 /// </summary>
 public void Clear()
 {
     _connection.Close();
     _connection.Dispose();
 }