Hi All,
I have some code that is using ADO.NET 2.0 and TableAdapters. The code is pretty simple and I occassionally get an exception i.e. 'The transaction has aborted.'. 
The number of tables are actually 4 and 2 of wchich are being updated and 
rest two only making insertions. tbl1, tbl2, tbl3 are DataTable variables of 
type MyTable1, MyTable2, MyTable3 which are geneated by Visual studio for 
strongly typed datasets. (Code is given below). This exception is very random and occurs after processing few thousand records. Any idea why this is 
happening and how it can be resolved.

Thanks in advance for your help.


using (System.Transactions.TransactionScope myTransaction = new 
                MyDataSetTableAdapters.MyTable1TableAdapter tbl1A = new 
MyDataSetTableAdapters.MyTable1TableAdapter ();
                tbl1A.Connection = myConn;
                tbl1A.InsCommandTimeout = 45;
                tbl1A.UpdCommandTimeout = 45;
                MyDataSetTableAdapters.Table2TableAdapter tbl2A = new 
MyDataSetTableAdapters.Table2TableAdapter ();
                tbl2A.Connection = myConn;
                tbl2A.InsCommandTimeout = 45;
                tbl2A.UpdCommandTimeout = 45;
                MyDataSetTableAdapters.Table3TableAdapter tbl3A = new 
MyDataSetTableAdapters.Table3TableAdapter ();
                tbl3A.Connection = myConn;
                tbl3A.InsCommandTimeout = 45;
                myTransaction .Complete();

Re: .NET Framework Data Access and Storage The Transaction has aborted.


I believe you would need to catch exception and log all the information in this case, including stack trace, to see what would be potential issue. Without this information it is hard to say anything.

Also, based on your code, I do not see the reason to use System.Transactions, because it is not distributed transaction. Open local database transaction using SqlTransaction class. It is lighter and will be sufficient in your case. System.Transactiobs is good when you have multiple distributed sources of the data and you need to accomplish task as atomic transaction

Re: .NET Framework Data Access and Storage The Transaction has aborted.


No one is responding, dont know why


First of all, thank you very much for your reply. Atleast someone replied.

Yes, you are right, that I need to catch this exception. That part was not in the code snippet I copied. I already caught the exception but in a calling method. That's why, I know what exception i am getting. Here is the log I got from the exception:

2/28/2007 9:40:14 PM: The transaction has aborted. (Message property of Exception)
2/28/2007 9:40:14 PM:    at MyNameSpace.MyClass.ProcessThisBatch() (Stacktrace of exception started here)
   at MyNameSpace.MyClass.StartProcessingBatches(String bName, BatchInfo bi, Boolean bCloseCon)

Yes, you are right that, I could have used SqlTransaction. But all new sample code in MSDN uses TableAdapters and TransactionScope that means the use of TransactionScope is encouraged. Moreover, the transaction is a lightweight untill some ditributed source enters the picture. So in this case, the transaction will never be promoted to a distributed transaction. Also the interesing fact is that in some cases the batch is commited properly (I see database changes) and I still get this exception. A batch may include like 500 records or so.  The signature of the method gived in the previous mail:

UpdateSource(MyDataTable1 tbl1, MyDataTable2 tbl2, MyDataTable3 tbl3) -----Throws excetpion

ProcessThisBatch()----Catches Exception Throws again.

StartProcessingBatches()----Logs exception

Do let me know, if you think some detail is missing.




Re: .NET Framework Data Access and Storage The Transaction has aborted.

Joost Ploegmakers

Hi Paraclete,

I'm having the same problem... I'm using System.Transactions.TransactionScope and occasionally i get the exception 'The transaction has aborted.'

Using the following code:

Code Snippet
TransactionScope(TransactionScopeOption.Required, IsolationLevel.ReadCommitted);

I get (sometimes, most of the times not) the following stacktrace:


stack trace
at System.Transactions.TransactionStateAborted.CreateAbortingClone(InternalTransaction tx)
at System.Transactions.DependentTransaction..ctor(IsolationLevel isoLevel, InternalTransaction internalTransaction, Boolean blocking)
at System.Transactions.Transaction.DependentClone(DependentCloneOption cloneOption)
at System.Transactions.TransactionScope.SetCurrent(Transaction newCurrent)
at System.Transactions.TransactionScope.PushScope()
at System.Transactions.TransactionScope..ctor(TransactionScopeOption scopeOption, TransactionOptions transactionOptions)


The transaction is not begin promoted.

Like you, i don't have a clue Smile ... i'm posting this just to let you know, you're not alone.

Re: .NET Framework Data Access and Storage The Transaction has aborted.



Though it took me longer time, but in my case it was show stopper to I had to resolve it. So here is what my findings/solution was.

In my case it was the 'time out'. The Transaction timed out becuase I was doing a bulk update in the database. Playing with the Transaction time out and the number of records in one batch. I have overcame this issue.

Find out what the innerexception is and what is the stacktrace for innerexception. This may reveal the cause of the transaction.



Re: .NET Framework Data Access and Storage The Transaction has aborted.

Mike Krysl

I know this is an old thread, but thought I would add something for those who may pass this way again. I was getting the same "transaction has aborted" error. After reading this thread I simply disabled my breakpoints and it worked just fine. As it turned out, debugging my code by stepping through it was causing a timeout error!