我想收回一个称为“镜子”的交易,但所标明范围2的内部交易不应退缩。 但是,他们都 back! 选项 TransactionScopeOption。 2. 禁止工作......
I already enabled DTC and I m using Visual Studio 2010 with .net 4.0 and Microsoft SQl Server 2008. What s wrong here???
using (SqlConnection conn = new SqlConnection(@"Data Source=.DEVELOPER;Initial Catalog=TestDatenbank;Integrated Security=sspi"))
{
using (TransactionScope scope = new TransactionScope())
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "UPDATE Orders SET ID= 111 ";
cmd.ExecuteNonQuery();
using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.Suppress))
{
SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = conn;
cmd1.CommandText = "UPDATE Orders SET OrderName= aaa ";
cmd1.ExecuteNonQuery();
scope2.Complete();
}
//scope.Complete();
}
}
感谢你们的回答。
最后我!
using (SqlConnection conn = new SqlConnection(@"Data Source=.DEVELOPER;Initial Catalog=TestDatenbank;Integrated Security=sspi"))
{
using (TransactionScope scope = new TransactionScope())
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "UPDATE Orders SET ID= 111 ";
cmd.ExecuteNonQuery();
using (SqlConnection conn2 = new SqlConnection(@"Data Source=.DEVELOPER;Initial Catalog=AdventureWorks;Integrated Security=sspi"))
{
using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.Suppress))
{
conn2.Open();
SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = conn2;
cmd1.CommandText = "UPDATE Henrik SET ID= 111 ";
cmd1.ExecuteNonQuery();
scope2.Complete();
}
}
//scope.Complete();
}
}
我删除线范围2时,有一点奇怪。 完成();取代//范围.Complete();范围。 完成();我希望:
scope will be executed scope2 will roll back
but actually: scope will be executed scope2 will also be executed
是否有任何想法?