Membership.GetUser() within TransactionScope throws TransactionAbortedException

Posted by Bob Kaufman on Stack Overflow See other posts from Stack Overflow or by Bob Kaufman
Published on 2010-03-21T14:36:29Z Indexed on 2010/03/21 14:41 UTC
Read the original article Hit count: 632

The following code throws a TransactionAbortedException with message "The transaction has aborted":

        using ( MyDataContext context = new MyDataContext() )
        {
            using ( TransactionScope transactionScope = new TransactionScope() )
            {
                Guid accountID = new Guid( Request.QueryString[ "aid" ] );
                Account account = ( from a in context.Accounts where a.UniqueID.Equals( accountID ) select a ).SingleOrDefault();
                IQueryable < My_Data_Access_Layer.Login > loginList = from l in context.Logins where l.AccountID == account.AccountID select l;

                foreach ( My_Data_Access_Layer.Login login in loginList )
                {
                    MembershipUser membershipUser = Membership.GetUser( login.UniqueID );
                }
            }   
        }

The error occurs at the call to Membership.GetUser().

My Connection String is:

      <add name="MyConnectionString" connectionString="Data Source=localhost\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=True"
   providerName="System.Data.SqlClient" />

Everything I've read tells me that TransactionScope should just get magically applied to the Membership calls. The user exists (I'd expect a null return otherwise.)

© Stack Overflow or respective owner

Related posts about transactions

Related posts about asp.net-membership