If there are no locks and multiple users access a database at the same time, problems may occur when their transactions use the same data at the same time. Concurrency issues include missing or overwriting updates, unacknowledged dependencies (dirty reads), inconsistent parsing (not repeating), and phantom reading. But how do you avoid the problem of dirty reading when data is read? Here is a brief introduction:
In a SQL Server database, there are four isolation levels: uncommitted read, commit read, repeatable read, serializable read. These four isolation levels guarantee concurrent data integrity to varying degrees:
The second is the default, and in the. NET Framework, the isolation level of the transaction is also supported. We can implement it through System.Data.IsolationLevel: public virtual IsolationLevel IsolationLevel {get;}
its members and the corresponding meanings are as follows:
Member name
Description
Value
Chaos
Supported by the. NET Compact Framework.
Cannot overwrite pending changes in higher isolation level transactions.
16
ReadCommitted
Supported by the. NET Compact Framework.
Keep a shared lock while reading data to avoid dirty reads, but you can change the data before the transaction ends, resulting in non repeatable read or phantom data.
4096
ReadUncommitted
Supported by the. NET Compact Framework.
You can do dirty reading, meaning that you do not publish shared locks and do not accept exclusive locks.
256
RepeatableRead
Supported by the. NET Compact Framework.
Locks are placed on all data used in the query to prevent other users from updating the data. Prevents unreadable reads, but can still have phantom rows.
65536
Serializable
Supported by the. NET Compact Framework.
Place a range lock on the DataSet to prevent rows from being updated by other users or inserting rows into the dataset before the transaction completes.
1048576
Unspecified
Supported by the. NET Compact Framework.
The isolation level that is different from the specified isolation level is being used, but the level cannot be determined.
-1
£
Obviously, the four isolation levels of the database are mapped here. In this case, the IsolationLevel default value for transactions such as SqlTransaction and OleDbTransaction is readcommitted. So how do we use it? You can implement this using the following methods:
Trans = Cnnorthwind.begintransaction (_
isolationlevel.serializable)
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