0
votes

I get following error randomly when executing code from debug mode.

Cannot access a disposed object.
Object name: 'SqlDelegatedTransaction'.
  • Error is being thrown after few commands have been executed instantly, not an timeout issue
  • I have just one transaction, opened with

    using(var scope = new TransactionScope(TransactionOption.Required))

  • Multiple connections are opened with same statement above in nested code.

  • i am using sqlserver 2008

What could be wrong?

1
You need to add some more details: show some more code, at what line in your code does this error occur? what were you doing/debugging (maybe changing the 'line to execute' to within that using block?). - Hans Kesting
Are you trying to call anything after you have exited the using block? After a using block, the object is diposed. I'd recommend going through your code and verifying that you haven't accidentally exited the using block with a misplaced '}'. - Jeffrey Lott

1 Answers

0
votes

When you use TransactionOption.Required the transaction joins the ambient transaction.

One possible theory is:

  • If you go through the transaction scope and do not call scope.Complete(), it will dispose the abmient transaction. The next code that tries to run against the database will then fail.

Another would be problems with respect to active result sets:

  • Are you using SQL Server 2000, which does not support Multiple Active Result Sets(MARS)
  • Does your connect string specify MultipleActiveResultSets= true