Membership.GetUser() within TransactionScope throws TransactionPromotionException
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
17:31 UTC
Read the original article
Hit count: 644
The following code throws a TransactionAbortedException
with message "The transaction has aborted" and an inner TransactionPromotionException
with message "Failure while attempting to promote transaction":
using ( TransactionScope transactionScope = new TransactionScope() )
{
try
{
using ( MyDataContext context = new MyDataContext() )
{
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 );
}
[... lots of DeleteAllOnSubmit() calls]
context.SubmitChanges();
transactionScope.Complete();
}
}
catch ( Exception E )
{
[... reports the exception ...]
}
}
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