views:

18

answers:

1

I use a TransactionScope in a thread to dump data in my SQL Server database.

using (TransactionScope scope = new TransactionScope())
{
    // Dump data in database
    scope.Complete();
}

The transaction is a long transaction (40 secondes) because data are bigs : that's normal.

When I do an Abort() to stop the thread during this transaction, SQL Server seems to be locked during a few minutes.

What's happened ?

How can I avoid that ?

+2  A: 

Simply said: you can not.

Server seems to be locked during a few minutes.

No. SQL Server is busy undoing your transaction. It is optimized fully to COMMIT transactions, not to undo them. Undoing LARGE updates is a SLOW operation. Depending on your server layout and the amount of data it can take some minutes or even hours.

All you can do is... not rollback / abort. Or wait.

TomTom
@TomTom : Ok, thank you ! If I kill my c# program, I have the same behaviour
Patrice Pezillier
As it should be. Any abort client side - and a kill of the program obviously is one - will trigger a rollback on the server side. The transaction was not commited ergo it is aborted.
TomTom
it's obvious, if you kill the program the tran remains not committed and will be aborted.
vaitrafra