Ben
Ben

Reputation: 3912

TransactionScope commits updates without calling .Complete() but not inserts

I have a transacationScope that surrounds some functions. These functions each do database calls of either inserts or updates.

 using (var ts = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
            {
                IsolationLevel =
                    IsolationLevel.Serializable,
                Timeout = new TimeSpan(0, 0, 15, 0)
            }))
            {
                    DoStuff(arg!, arg2);
                    ts.Complete(); //This had to be added to commit the changes for inserts (updates worked), otherwise data was being rolled back
            }

With ts.Complete(); inserts and updates are committed to the database, without only updates are. Could someone please explain why?

Upvotes: 3

Views: 1934

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1063393

That suggests your updates are not part of the transaction. That could mean:

  • the updates were done on a connection that already existed before you started the transaction-scope
  • there was an explicit nested new-transaction or no-transaction
  • unicorns

To confirm: without the Complete, nothing in the transaction is committed

Upvotes: 4

Related Questions