Handling of concurrent update conflicts

Source: Internet
Author: User

Statement, if there are any omissions, it would be quite natural. After all, my skills are limited, and there are still many areas to improve. I hope you will not give me any corrections!

 

I.Why is concurrency?

When we useAdo.netWhen performing operations on the data in the database, it is very likely that such operations or similar operations are also

Other users in the Network may encounter update failures. Because in order to improve performance,Ado.netThe connection is closed. That is to say, to read the data copy to the client, it is easy for multiple users to update a record at the same time to produce data concurrency exceptions. This operation may be because another user has deleted the row record or modified a field. This is a high-level topic and has always been a difficult topic in data operations. Below I will only discuss and analyze it briefly.

II.Solution

Generally, there are two methods to handle concurrency conflicts. One is synchronous concurrent processing, and the other is open concurrent processing. Institute

The concurrent processing is to use a lock to lock a record until the user submits an update. Its disadvantage is quite conservative, just like its name. Because if the user leaves or forgets to update the data after reading the data, other users have to wait, until he is back, reminded, or remembered. Obviously, this is not what we want to see (of course, this method also has its advantages under specific requirements and conditions, otherwise it will not be necessary ). On the contrary, open concurrency is the focus of our discussion.Ado.netRecommended method. What is an open concurrent processing method? In my own understanding, we need to deal with the emergence of concurrency exceptions, and develop a solution to solve or prompt users for such exceptions. Since concurrency is inevitable, we need to make a good solution to handle concurrency conflicts. This is like an optimistic person. If he has a disease, his mind is still optimistic, he wants to focus on how to treat it, rather than completely avoiding it (this metaphor may not be appropriate, just laugh! Haha ). Before writing a program, consider the possibility of concurrency. Select the update logic and method as needed.

III.Attention should be paid to open concurrent processing. (This is also the most likely cause of problems. Please give me more comments !)

 

1.Update Method SelectionGenerally, there are two update Methods: cache update and instant update. Cache update is usedDataadapter. updte ()Method to update data. We mayDatagridBut only one commit operation is performed. If this operation starts from Data Reading (or the last update operation, it is more likely to cause concurrency conflicts. Relatively speaking, update immediately, that is, useCommand.exe cutenoquery ()Method to directly submit modifications to a record. However, conflicts cannot be completely avoided, but they are still recommended by me.

2.Update logic Selection  Update logic: I understand which update method is used to update data. It can contain all columns; it can only contain primary key columns; it can contain primary key columns and updated columns; it can contain primary key columns and timestamp columns. Let's look at this4Differences in the update logic. If you have usedPbIt is easier to understand. BecausePbThere are many similarities between the three update logics. To better illustrate the problem, let's give an example. Tables

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.