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)