- I am developing an application in C# WPF which will have Client-Server architecture (Client will do products sales billing). I am novice in this area and I asked this question to start my development process.
Click here to view question.
So, ultimately I have selected MySQl, WCf & WPF. Now I have one silly question. Do i need to handle DB concurrency explicitly in my application (like 3 clients inserting data same time) or MySQl will handle this without any conflict? - To accomplish my project i thought, I will create a service in WCf which will do DB queries from client application. Do you have any suggestion to improve my application performance.
3 Answers
With respect to your question about concurrency, your application should be designed to keep connections to the database open as short as possible. Each action on the database should involve: open connection, act on the database, close the connection rather than: open connection, do a bunch of work that may or may not be related to getting/updating/inserting data and then at "the end" close the connection.
Now, with respect to application concurrency, you end up with two scenarios. In scenario one, which I'll call "last write wins", whatever connection writes to a given row last is the version of the data that gets stored. If Alice then Bob write to the Name column on the same row at the same time, Bob's version will be what is stored. This is by far the simplest but if you might have a lot of people updating the same data, it might be problematic.
An alternative is "first write wins" also called Optimistic Concurrency. In this scenario, the second call checks that the data has not changed since it was last retrieved and if it has, then its transaction is rolled back. What happens next depends on your application. Some systems simply throw an error and require the user to re-enter their information (discarding their original change). This is obviously easier to implement. Some applications tell the user that the data has changed and provide some information about what is different and ask whether they want to overwrite this change. That can be more complicated depending on the architecture of your system.
See Optimistic Concurrency for more.

- 63,911
- 12
- 95
- 141
There are a number of ways to handle concurrency, each with their pro's and con's.
This article gives a good general introduction.
If you wish to share more about your requirements around concurrency:
- What do you WANT to happen when multiple people try to edit the same data?
- How frequently do you expect users to edit the same data?
I would be glad to give more specific advice.

- 147,927
- 63
- 340
- 553
- Database servers are pretty good at handling multiple updates.
- Use netTcpBinding.

- 1,023,142
- 271
- 3,287
- 2,928
-
@Darin: 1. is a very broad statement and doesn't account for the specific application needs. Do you have reasons for 2.? – Eric J. Apr 10 '10 at 17:59
-
@Eric J., specific application needs haven't been expressed in the question. The OP asked if MySQL will handle 3 concurrent inserts and the answer to this is yes. As for point 2: http://www.netfxharmonics.com/2006/01/WCF-Relative-Binding-Speeds.aspx – Darin Dimitrov Apr 10 '10 at 18:01
-
If User A opens a form to edit data, and User B changes the data that User A has opened for editing, then User A saves his changes... what happens? That's what the OP is asking. Do you inform User A that a change has been made? Do you lock that data for changes so that User B could never have opened it for changes in the first place? – Eric J. Apr 10 '10 at 20:24