I'm using TransactionScope
to do some batch insert and updates. Problem is, I'm getting timeout exceptions on a 30 min long operation even when I set the timeout of the TransactionScope
to one hour.
Also after the exception it inserts seemingly random amount of the records of the batch. For example the last operation had 12440 inserts and after the timeout there were 7673 records inserted to the table.
The timeout of the SqlConnection
and SqlCommand
are both set to int.MaxValue
.
What am I doing wrong?
Here's my code:
using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromHours(1)))
{
try
{
using (db = new DB())
{
//operations here
}
}
catch (Exception ex)
{
throw new Exception("DB Error:\r\n\r\n" + ex.Message);
}
transaction.Complete();
} // <--- Exception here: Transaction aborted (Inner exception: Timeout)