My Code something like this
try
{
using (TransactionScope iScope = new TransactionScope())
{
try
{
isInsertSuccess = InsertProfile(account);
}
catch (Exception ex)
{
throw;
}
if (isInsertSuccess)
{
iScope.Complete();
retValue = true;
}
}
}
catch (TransactionAbortedException tax)
{
throw;
}
catch (Exception ex)
{
throw;
}
Now what happen is that even if my value is TRUE a TransactionAbortedException Exception occurs randomly, but data get’s inserted/updated in DB.
Any idea what went wrong?
As the
TransactionAbortedExceptiondocumentation says,This is why you see the exception even after calling
Transaction.Complete: theCompletemethod is not the same thing asCommit:The transaction isn’t committed until you exit the using statement: see the
CommittableTransaction.Commitdocumentation for details. At that point any actions participating in the transaction may vote to abort the transaction and you’ll get aTransactionAbortedException.To debug the underlying problem you need to analyze the exception details and stack trace. As Mark noted in a comment, it may well be caused by a deadlock or another interaction with other database processes.