This exception cannot be debugged without a full stack trace. It depends on the context. This usually means that you are doing something that should not be inside the transaction, but without seeing the db calls or the stack trace, all you can do is guess. Some common reasons that I know about (and this is far from complete, I'm sure) include:
- Access to multiple data sources (i.e. different connection strings) inside a nested
TransactionScope . This causes a move towards a distributed transaction, and if you do not perform DTC, it will not work. The response, as a rule, does not include DTC, but to clear a transaction or transfer another data access using the new TransactionScope(TransactionOptions.RequiresNew) . - Unhandled exceptions in
TransactionScope . - Any operation that violates the isolation level, such as reading rows inserted or updated.
- SQL deadlocks; Transactions can even come to a standstill in certain cases, but if No. 1 is applied, allocating other operations in new transactions can lead to locks if you are not careful.
- Transaction timeouts.
- Any other error from the database.
I definitely do not know every possible reason, but if you put the full stack trace and the actual db calls in your code, I will take a look and let you know if I see anything.
AndyM
source share