【发布时间】:2014-02-14 05:37:30
【问题描述】:
当使用 TransactionScope 时,如果内部执行的代码回滚事务,那么父事务也会回滚。这对我有好处。但是在处理该范围时,它会引发异常,这意味着事务已经回滚并中止。 那么处理该问题并正确处置范围的正确方法是什么?
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
using (var conn = GetConnection())
{
string query =
@"some query that may contain transaction itself
or some SP whith transaction included"
using (var command = new SqlCommand(query, conn))
command.ExecuteNonQuery();
}
}
scope.Complete();
} // Exception here
【问题讨论】:
标签: c# sql transactions