【问题标题】:Will the nested transactions be rolled back when the root one rolls back?当根回滚时,嵌套事务是否会回滚?
【发布时间】:2012-07-21 10:17:51
【问题描述】:

在这段代码中..

public static TransactionScope CreateTransactionScope(bool createNew = false)
{
    return new TransactionScope(
        createNew ? TransactionScopeOption.RequiresNew : TransactionScopeOption.Required,
        new TransactionOptions() { IsolationLevel = IsolationLevel.ReadCommitted });
}

其实在这...

using (TransactionScope rootScope = CreateTransactionScope())
{
    using (TransactionScope nestedOne = CreateTransactionScope())
    { nestedOne.Complete(); }

    using (TransactionScope nestedTwo = CreateTransactionScope(true))
    { nestedTwo.Complete(); }

    // No committing, rollback 'rootScope'.
}

哪些事务将与根事务一起回滚 - 是只有 nestedOne 还是 nestedOnenestedTwo

【问题讨论】:

    标签: c# sql-server transactions transactionscope rollback


    【解决方案1】:

    nestedOne 会加入根作用域,所以如果根作用域回滚,nestedOne 也会回滚,但nestedTwo 不会,它是一个单独的事务。

    就像您有将事务与封闭事务分开的“RequireNew”选项一样,您可以使用“Suppress”选项来停止该范围内的事务。

    查看 MSDN 中的以下列表,该列表提供了有关事务行为的重要课程。 http://msdn.microsoft.com/en-us/library/ms172152(v=vs.90).aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多