none
Nested Transactions Question RRS feed

  • Question

  • I have a hierarchy of business classes where each has a Save() function and each Save() function using a transaction as such:

    using (TransactionScope scope = new TransactionScope())
    {
     <snip> . . .

     scope.Complete();
    }

    In my Unit Test application, this works fine, but in my ASP.NET application, the first nested TransctionScope instantiation crashes with a "Transaction has been aborted" message.

    My connection string contains "MultipleActiveResultSets=true" like I think it should and the DTC service is running on the web server.

    Maybe a more useful message would be helpful . . .

    Anyone have an idea what might be happening here? Is there a database setting that might cause this? The web app uses a different physical environment including a different database.

    Help is appreciated.

    Vic

    Tuesday, May 11, 2010 11:43 AM

All replies

  • Some more clarification, in hopes that someone can help.

    Here's the model:

    public class Parent
    {
     protected MYCONTEXT _db = new MYCONTEXT(MYCONNECTIONSTRING);
     public virtual bool Save(ref string message)
     {
         try
         {
      using (TransactionScope scope = new TransactionScope())
      {
       /* Set a bunch of data in a DataContract class */
       
       _db.SubmitChanges();

        scope.Complete();
      }
      return true;
         }
         catch (Exception exc)
         {
      message = Utility.ParseException(exc)[0];
      return false;
         }
     }
    }

    public class Child
    {
     public override bool Save(ref string message)
     {
         try
         {
      using (TransactionScope scope = new TransactionScope())
      {
       /* Set a bunch of data in a DataContract class */
       _db.SubmitChanges();

          if (!base.Save()) return false;

          scope.Complete();
      }
      return true;
         }
         catch (Exception exc)
         {
      message = Utility.ParseException(exc)[0];
      return false;
         }
     }
    }

    When I run this from my box, where the web app and the database are on the same box, it works fine. When I point to a Sql Server on an external box, it crashes on " using (TransactionScope scope = new TransactionScope())" in the Parent class.

    I don't have 100% control over all of the boxes, but I'm told that DTC is running everywhere.

    This isn't an AppDomain problem, is it? The business logic doesn't have to reside on the same box as the database, does it?

    Help is appreciated.

    Thanks,

    Vic

    Tuesday, May 11, 2010 6:27 PM
  • Could be a DTC permissions issue; even if MSDTC is running on all systems involved they may not be able to communicate if not granted permission...
    Kristofer - Huagati Systems Co., Ltd.
    Cool tools for Linq-to-SQL and Entity Framework:
    huagati.com/dbmltools (add-in with new features for the L2S and EF designers in VS2008 and VS2010)
    huagati.com/L2SProfiler (Query profiler for Linq-to-SQL and LLBLGen Pro)
    Wednesday, May 12, 2010 3:23 AM
    Answerer