Commit and rollback Oracle transactions

I call this proc in C # from oracle. I made proc return an error. In other words, proc fails, and pv_error fills with a string, and the rollback starts, but does not work. I do not know why. So what am I doing wrong? Thanks in advance.

private void hhrcv_update_dc_grs_carton()
    {
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        conn.Open();
        OracleTransaction trans = conn.BeginTransaction();
        cmd.CommandTimeout = 0;
        cmd.CommandText = "dc.hhrcv_update_dc_grs_carton";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("pn_dc_grs_no", OracleDbType.Number).Value = txtDcGRSNo.Text;
        cmd.Parameters.Add("pn_pallet_id_no", OracleDbType.Number).Value = txtPalletId.Text;
        cmd.Parameters.Add("pn_carton_code", OracleDbType.VarChar).Value = txtCartonCode.Text;
        cmd.Parameters.Add("pn_company_id_no", OracleDbType.Number).Value = Companyid;
        cmd.Parameters.Add("pn_order_no", OracleDbType.Number).Value = txtOrderno.Text;
        cmd.Parameters.Add("pn_emp_id_no", OracleDbType.Number).Value = empid;
        cmd.Parameters.Add(new OracleParameter("pv_error", OracleDbType.VarChar));
        cmd.Parameters["pv_error"].Direction = ParameterDirection.Output;
        string pv_error;
        cmd.ExecuteNonQuery();
        pv_error = cmd.Parameters["pv_error"].Value.ToString();

        if (pv_error.ToString() == "")
        {
            trans.Commit();
        }
        else
        {
            trans.Rollback();
            MessageBox.Show("" + pv_error, "Error");
            frmReturns r = new frmReturns();
            r.Show();
            this.Hide();
        }
    }
  • Stored procedure does not commit
  • Autostart SQL SQL developers disabled.
  • When I run the stored procedure in Oracle SQL developers, it works (crash - how I did it and don’t commit it)
  • Only when starting a stored procedure in VS2005 does the process fail, start the rollback, but do not execute it
+6
source share
2 answers

Most likely you need to add:

cmd.Transaction = tran;

after the call BeginTransaction.

, cmd tran!

. .

+8

, Autocommit .

Oracle

, Commit SQL; , . - true.

, ,

conn.Autocommit=false;
+1

All Articles