Small pitfalls in transaction debugging

Source: Internet
Author: User
Tags sql server query
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.