Rohit Raghuvansi
Rohit Raghuvansi

Reputation: 2864

What happens if network is lost while rolling back transaction with TransactionScope in .Net

I have this following code:-

 using (var transactionScope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required))
        {
            bool IsCreated=false;
            context.CommandTimeout = 120;
            if(IsCreated)
              transactionScope.Complete();                             
        }

Now If transactionScope.Complete() is not called, Transaction is rolled back once scope of using is Complete. However IF before this there is a network outage, how will this transaction be rolled back. It is rolled back as i tried removing the network cable but i dont understand how is it getting rolled back. According to my understanding if Transaction is not commited within the commandtimeout it is rolled back by sql server. Please validate.

Upvotes: 1

Views: 125

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1063338

The CommandTimeout only impacts commands issued - not the overall transaction. DTC has a timeout (also available via some constructor overloads), but that is mainly intended for distributed deadlock scenarios.

In this scenario, I suspect it is more a case that the controller is keeping tabs on all the systems involved, and reporting failure if any of them fail to respond / keep in touch.

Upvotes: 1

Related Questions