TransactionScope Precautions for use (RPM)

Source: Internet
Author: User

First, in TransactionScope, if it is not necessary to prevent it from enabling DTC distributed transactions because of poor performance, and for TransactionScope it is a Connection object connection as the identity unit, That is, even if the same connection string connectionstring two Connection objects connection in TransactionScope will also enable the DTC distributed transactions, The way to avoid this is to use a unique connection object connection in a TransactionScope.


Second, the default transaction level in TransactionScope is serializable, which is the complete lock table during the transaction process. Other processes can not query, modify, add, delete. This results in a significant reduction in efficiency, although data integrity is high. Usually we don't need that high data integrity. Therefore, the default transaction level needs to be modified:

transactionoptions Option= NewTransactionoptions ();
Option. IsolationLevel=System.Transactions.IsolationLevel.ReadCommitted;
using(TransactionScope ts= NewTransactionScope (transactionscopeoption.required, option))


All the transaction levels are as follows:

Member name Description
Chaos cannot overwrite pending changes in a transaction with higher isolation levels.
ReadCommitted can not read mutable data during a transaction, but it can be modified.
ReadUncommitted can read and modify volatile data during a transaction.
RepeatableRead can read mutable data during a transaction, but it cannot be modified. You can add new data during a transaction.
Serializable can read mutable data during a transaction, but it cannot be modified or any new data can be added.
Snapshot can read variable data. Before a transaction modifies data, it verifies that the data has been changed by another transaction after it originally read the data. If the data has been updated, an error is raised. This enables the transaction to obtain the previously committed data value.
When you attempt to promote a transaction created at this isolation level, a invalidoperationexception is raised and an error message is generated, "Transactions with IsolationLevel Snapshot cannot is Promoted "(Cannot promote a transaction with a IsolationLevel snapshot).

Unspecified is using a different isolation level than the specified isolation level, but the level cannot be determined. If this value is set, an exception is thrown.

TransactionScope Precautions for use (RPM)

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.