Informix .NET Provider和TransactionScope不回滚 [英] Informix .NET Provider and TransactionScope not rolling back
问题描述
我有一个概念验证的分布式事务应用程序,它可以简单地插入两个表中-一个是MS SQL Server表,另一个是Informix Dynamic Server表.当引发异常时,问题就来了.如果我将OLE DB驱动程序用于Informix,则一切正常-两个插入都回滚;如果我将.NET数据提供程序用于Informix,则Informix插入不会回滚.
I have a little proof-of-concept distributed transaction application that is doing a simple insert into two tables -- one a MS SQL Server table, the other an Informix Dynamic Server table. The problem comes when an exception is thrown. If I use the OLE DB driver for Informix, everything works fine -- both inserts roll back; if I use the .NET Data Provider for Informix, the Informix insert does not roll back.
有人对发生的事情有任何想法吗?
Does anyone have any ideas as to what is going on?
在代码段中,您会注意到注释掉的EnlistTransaction()方法.显式调用时,出现异常,表明该方法未实现.
In the code snippet, you will notice the commented-out EnlistTransaction() method. When explicitly called, I get an exception indicating that the method is not implemented.
代码段:
private void doTransaction(Boolean commitIndicator)
{
using (TransactionScope tscope = new TransactionScope())
{
using (SqlConnection cn = new SqlConnection { ConnectionString = sql2008Settings.ConnectionString })
{
cn.Open();
using (SqlCommand cmd = cn.CreateCommand())
{
cmd.CommandText = "insert into uom (uom) values ('Test')";
int count = cmd.ExecuteNonQuery();
}
}
using (IfxConnection cn = new IfxConnection())
{
cn.ConnectionString = idnSettings.ConnectionString;
cn.Open();
//cn.EnlistTransaction(Transaction.Current);
using (IfxCommand cmd = cn.CreateCommand())
{
cmd.CommandText = "insert into table_ (code_, description) values ('JEP', 'Test')";
int count = cmd.ExecuteNonQuery();
}
}
if (commitIndicator)
{
}
else
{
throw new Exception("planned failure");
}
tscope.Complete();
}
}
连接字符串:
Connection Strings:
推荐答案
我非常确定Informix .Net ADO Provider不支持TransactionScope.这不是ADO.Net提供程序的要求.
I'm pretty sure that the Informix .Net ADO Provider doesn't support TransactionScope. It's not a requirement of an ADO.Net provider.
由于Informix确实支持COM +和MSDTC,因此您可以使用COM +和MSDTC使其工作.您需要执行以下操作:
You might get this to work by using COM+ and MSDTC, since the Informix does support that. You'll need to do the following:
- 在连接字符串中添加"enlist = true"
- 将
EnterpriseServicesInteropOption.Full
添加到您的TransactionScope
构造函数中
- Add "enlist=true" to your connection string
- Add
EnterpriseServicesInteropOption.Full
to yourTransactionScope
constructor
这篇关于Informix .NET Provider和TransactionScope不回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!