我正在通过引发新的Exception(如果事务是否回滚)来实践TransactionScope,即使scope2具有抑制选项,scope1也不会提交。我期望两个sqlcommand块将被提交。我的代码有什么问题?
using (TransactionScope scope1 = new TransactionScope(TransactionScopeOption.Required))
{
using (SqlConnection conn = new SqlConnection(AppGlobalVariables.CONNECTION_STRING))
{
//success sqlcommand...
}
using (SqlConnection conn = new SqlConnection(AppGlobalVariables.CONNECTION_STRING))
{
//success sqlcommand...
}
using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.Suppress))
{
//this throws new Exception(string)
ThrowAnError("Scope 2 Error");
}
scope1.Complete();
}