Transactions in MySQL - Unable to Roll Back

I am using MySQL 5.0.27 and trying to get transactions to work. I followed this guide:

http://dev.mysql.com/doc/refman/5.0/es/connector-net-examples-mysqltransaction.html

and still can't get them to work. The table I'm trying to update is InnoDB and tried to execute "set autocommit = 0" but it doesn't seem to do anything .... The code I wrote is as follows:

public int transactionUpdate() { MySqlConnection connection = new MySqlConnection(connStr); connection.Open(); MySqlCommand command = connection.CreateCommand(); MySqlTransaction trans; trans = connection.BeginTransaction(); command.Connection = connection; command.Transaction = trans; try { command.CommandText = "SET autocommit = 0"; command.executeNonQuery(); command.CommandText = "UPDATE TBL.rec_lang rl SET rl.lang_code = 'en-us' WHERE rl.recording=123456"; command.executeNonQuery(); command.CommandText = "UPDATE TBL.rec_lang rl SET rl.lang_code = en-us WHERE rl.recording=123456"; command.executeNonQuery(); trans.Commit(); } catch(Exception ex) { try { trans.Rollback(); } catch(MySqlException mse) { log.error(mse); } } } 

The second command fails because it lacks' around 'en-us'. This should drop the first request to the previous value, but it is not. Can you tell me what I am doing wrong?

MySQLConnector v. 6.3.6.0

MySQL v. 5.0.27

C # VS2010

+6
c # mysql transactions rollback
source share
1 answer

I had an open second database that had bad data showing> <... this method works. Turns out I don't even need to:

 command.CommandText = "SET autocommit = 0"; command.executeNonQuery(); 

So this code works for transactions.

+4
source share

All Articles