MySQL的交易 - 无法回滚 [英] Transactions in MySQL - Unable to Roll Back
问题描述
我在使用MySQL 5.0.27和我试图让交易工作。我跟着这个教程:
I'm using MySQL 5.0.27 and am trying to get transactions to work. I followed this tutorial:
的 http://dev.mysql.com/doc/refman/5.0/es/connector-net-examples-mysqltransaction.html
,但仍无法得到这些工作。我想更新该表是InnoDB和试图执行设置自动提交= 0',但它似乎并没有被做任何事情....我写的代码如下:
and still cannot get these to work. The table I am trying to update is InnoDB and have tried to execute 'set autocommit=0' but it doesn't seem to be doing anything.... The code I've written is the following:
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);
}
}
}
第二个命令失败,因为它缺少围绕EN-US。这应该回退所述第一查询,以及到先前的值,但事实并非如此。你能告诉我什么我做错了?
The second command fails as it is missing the ' around 'en-us'. This should roll back the first query as well to a previous value but it isn't. Can you tell me what I'm doing wrong???
MySQLConnector诉6.3.6.0
MySQLConnector v. 6.3.6.0
MySQL的诉5.0.27
MySQL v. 5.0.27
C#VS2010
推荐答案
我有一个第二个数据库打开了坏数据显示>< ...这种方法可行:)。原来我甚至没有需要:
I had a second database open that had bad data showing ><... this method works :). Turns out I didn't even need:
command.CommandText = "SET autocommit = 0";
command.executeNonQuery();
因此,好消息是这样的代码并进行交易工作......坏消息我没有图它直到我张贴;)
So the good news is this code does work for transactions... bad news i didn't figure it out until i posted ;)
这篇关于MySQL的交易 - 无法回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!