At the beginning of. net2.0, there was direct support for transactions. We no longer needed COM + transactions for transaction management, and transactionscope became a class that I often use. Generally speaking, I know the commit and rollback of the transaction clearly, but there was an accident during debugging today. To ProgramA new method A is added, and A is called by the method in a transaction. That is to say, the execution of a is a step of the transaction (it has many pre-steps ). There is a very simple query in A and returns an id I need. I am very familiar with my own data and know what the returned value of this ID is. But I was surprised to find that this ID is not the value I imagined during the single-step debugging. I captured the query string at run time and put it in the SQL Server Query analyzer for execution. I found my memory was okay.
At this time, I felt very strange: Why is the same query in CodeRunning in analyzer and query analyzer will have different results? In fact, the two different results are "correct. When the program runs to the breakpoint, the data has been changed by the Pre-operations in the same transaction. When I run the data in the query analyzer, the transaction has been rolled back due to timeout, so what I see is the old data.
The default transaction timeout of. NET is one minute, which is not enough for debugging and can easily time out. You can set it in the <system. Transaction> Configuration section of Web. config or the transactionscope constructor.