locked
TransactionScope and EntLib RRS feed

  • Question

  • User-527960386 posted

     I do transaction in the business layer, and I use EntLib's DAAB.

    This gives me some problems, namely a InvalidOperationException: "ExecuteNonQuery requires an open and available Connection. The connection's current state is closed."

    I've tried both using the TransactionScope, and the ServiceConfig way of doing COM+ transactions.

    It works fine without the transaction stuff, but as soon as I turn it on I get the exception. The transaction code is:

     

     

    using(TransactionScope scope = new TransactionScope())
    {
    MembershipUser createdUser = Membership.CreateUser(userName, password, email);
    createdUser.Comment = comment;
    Membership.UpdateUser(createdUser);
    Roles.AddUsersToRole(new string[]{createdUser.UserName}, "Administrator");
    rows = DataAccessFactory.GetAdministratorDao().Insert((Guid)createdUser.ProviderUserKey, firstName, middleName,
    lastName,
    address1, address2, postalCode, city, country);
    DataAccessFactory.GetPhoneNumberDao().Insert((Guid)createdUser.ProviderUserKey, phoneNumberCollection);
    scope.Complete();
    }
      


    I'm well aware that the connection gets closed since I do transaction from the business layer, but that should be possible, even if it then becomes a distributed transaction.

     Im'm wondering if it's DAAB that's screwing things up.

    Any good advice?

    Tuesday, April 15, 2008 2:14 PM

All replies

  • User-527960386 posted

     I solved it.

    I closed the connection myself explicitly in my DAL, but version 3.1 of EntLib takes care of closing the connections and so I messed it all up somehow when I did so explicitly.

     A good case of "you create it - you close it" I guess. :)
     

    Tuesday, April 15, 2008 3:15 PM