[英]ODBC transaction does not roll back
I have referred this to perform rollback operation in my wpf c# application. 我已经将此引用在我的wpf c#应用程序中执行回滚操作。 The code that I tried is as follows: 我尝试过的代码如下:
using (OdbcConnection connection = new OdbcConnection("connectionString"))
{
OdbcCommand command = new OdbcCommand();
OdbcTransaction transaction = null;
command.Connection = connection;
try
{
connection.Open();
transaction = connection.BeginTransaction();
command.Connection = connection;
command.Transaction = transaction;
command.CommandText = "INSERT INTO TableA (A, B, C) VALUES (10,10,10)";
command.ExecuteNonQuery();
command.CommandText = "NSERT INTO TableB (D,E,F) VALUES (20,20,20)";
command.ExecuteNonQuery();
transaction.Commit();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
try
{
transaction.Rollback();
}
catch
{
}
}
Intentionally the second query has been made wrong. 故意第二个查询已出错。 My intention is that when I enter the catch block on calling transaction.Rollback() the values added due to executing of the first query in TableA are not reflected since Rollback was called. 我的意图是,当我在调用transaction.Rollback()时进入catch块时,由于调用了Rollback,因此未反映由于执行TableA中的第一个查询而增加的值。 However this is not the case the values are not rolledback and are present in TableA. 但是,不是这种情况,即值未回滚并存在于TableA中。 I have searched various resources online with no luck. 我没有在网上搜索各种资源。 I cannot use SqlConnection instead of OdbcConnection my application does not support that. 我不能使用SqlConnection代替OdbcConnection,我的应用程序不支持该功能。 Is there any work around this or alternative method that can achieve what I have in mind. 是否有任何围绕此方法或替代方法的工作可以实现我的想法。 Please help me out. 请帮帮我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.