3.30 notes on using transaction in ASP. NET

Source: Internet
Author: User

Tip: The usage principle of transaction, which is used only when the program needs it. for example, if you simply retrieve data from a database or perform a simple query, you do not need to use transaction. On the other hand, if you insert data in several associated tables, you need to use transactions. generally, we do not use transactions for a simple operation, such as update, delete, or insert.

Even though ADO. NET provides good support for transactions, you shoshould not always use transactions. in fact, every time you use any kind of transaction, you automatically incur some overhead. also, transactions involve some kind of locking of table rows. thus, unnecessarily using transactions may harm the overall scalability of your application. when implementing a transaction, you can follow these practices to achieve the best results:
• Keep transactions as short as possible.
• Avoid returning data with a SELECT query in the middle of a transaction. Ideally, you should return the data before the transaction starts.
• If you do retrieve records, fetch only the rows that are required so as not lock too into resources and so as to keep performance as good as possible.
• Wherever possible, write transactions within stored procedures instead of using ADO. net transactions.
• Avoid transactions that combine multiple independent batches of work. Put separate batches into separate transactions.
• Avoid updates that affect a large range of records if at all possible.

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.