Groups > Asp .Net > Data Access and ObjectDataSource Control > Re: odbc trasaction commit and rollback




odbc trasaction commit and rollback

odbc trasaction commit and rollback
Wed, 2 Apr 2008 16:31:30 +0000
hi, 

i am using following code to insert the data into MySql database but its not
working properly on execution of execute reader only the data is getting
committed its not waiting for transaction to commit

or rollback

Actually while executing i am getting error in second insert so the data should
rollback but data is not getting rollback

try

{OdbcConnection MyConnection = newOdbcConnection("" +
Application["ConnectionString"].ToString() + "");

MyConnection.Open();

//creating and starting odbc transactionOdbcTransaction quote_trans =
MyConnection.BeginTransaction();

try

{

//insert command for database insertion of quotation detailsOdbcCommand
cmd_quote = newOdbcCommand();

cmd_quote.Transaction = quote_trans;cmd_quote = newOdbcCommand("Insert into
br_quotation_detail ( quotation_id, customer_id, quotation_date, enquiry_date,
excise, sales_tax, transportation_cost, payment_term, validity, enquiry_no,
created_by, creation_date, validtyterm, payterm) values ( '" +
tb_quotationid.Text.ToString() + "', (select customer_id from
br_customer_details where customer_name = '" +
ddl_custname.SelectedItem.Text.ToString() + "' and location = '" +
ddl_location.SelectedItem.Text.ToString() + "'),'" +
quote_date.ToString() + "', null, '" + tb_exciseduty.Text.ToString() +
"', '" + tb_salestax.Text.ToString() + "', '" +
tb_transcost.Text.ToString() + "', '" + tb_payterms.Text.ToString() +
"', '" + tb_validity.Text.ToString() + "', '" +
tb_enquiryno.Text.ToString() + "', '" + created_by.ToString() +
"', '" + creation_date.ToString() + "', '" +
ddl_validity.SelectedValue.ToString() + "', '" +
ddl_payterm.SelectedValue.ToString() + "')", MyConnection, quote_trans
);

//executing insert command

cmd_quote.ExecuteReader();

//declaring different objects of diff. control types

//loop to take values from each rfow of the datagridforeach (DataGridItem dgi in
dg_quotation.Items)

{

//taking values from datagrid into controls defined abovelb_productid =
(Label)dgi.FindControl("Label8");

lb_amendno = (Label)dgi.FindControl("Label2");tb_unitrate =
(TextBox)dgi.FindControl("Label5");

lb_unit = (Label)dgi.FindControl("Label4");tb_devcost =
(TextBox)dgi.FindControl("Label6");

tb_quantity = (TextBox)dgi.FindControl("Label7");

//storing the values into variables defined above

productid = lb_productid.Text.ToString();

amendno = lb_amendno.Text.ToString();

unitrate = tb_unitrate.Text.ToString();

unit = lb_unit.Text.ToString();

devcost = tb_devcost.Text.ToString();

quantity = tb_quantity.Text.ToString();

//insert command for database insertion of parts in quotationcmd_quote =
newOdbcCommand("Insert into br_quotation_part_detail ( quotation_id,
part_id, amd_id, unit_rate, unit, quantity, dev_cost, created_by, creation_date)
values ('" + tb_quotationid.Text.ToString() + "', '" +
productid.ToString() + "', '" + amendno.ToString() + "', '"
+ unitrate.ToString() + "', '" + unit.ToString() + "', '" +
quantity.ToString() + "', '" + devcost.ToString() + "', '" +
created_by.ToString() + "', '" + creation_date.ToString() +
"')", MyConnection);

//executing insert command

cmd_quote.ExecuteReader();

}

//Commiting transaction

quote_trans.Commit();

}catch (Exception ex)

{

//Rollbacking transaction in case of error

quote_trans.Rollback();

//Catching Exception if any and displaying the
messageClientScript.RegisterStartupScript(Page.GetType(), "msg",
"alert('Invalid Data');", true);

}
Post Reply
Re: odbc trasaction commit and rollback
Wed, 2 Apr 2008 18:24:52 +0000
First use the method ExecuteNonQuery instead of ExecuteReader.

ExecuteReader is use to read data from a select query.
Post Reply
Re: odbc trasaction commit and rollback
Thu, 3 Apr 2008 14:30:59 +0000
sorry for the silly mistake but the code is still not working please help me its
urgent
Post Reply
Re: odbc trasaction commit and rollback
Thu, 3 Apr 2008 14:39:56 +0000
Can you indicate the error that is happening and on what line?
Post Reply
Re: odbc trasaction commit and rollback
Thu, 3 Apr 2008 16:59:22 +0000
when second insert statement in the code gets executed it is raising exception
and going to catch block where the transaction should rollback but the
transaction is not rolling back it is committing the the value of first insert
statement
Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact