Asked by:
How to allo two comp to write into database at a same time?

Question
-
Hi all,
I have a program -> it is stored in personal cloud -> to this cloud are connected three, sometimes more computers -> this program, written in C# of course, use sometimes more computers so they fill out some fields and try to store data ... BUT when they do it at the sometime ... it couse an error ... different computer = different data ... saved data from on PC are sometimes same as saved data from another PC (but it filled different data) ... How to allow more comp access to the database at the same time?
I hope you understand my question ... what I need to solve ... thank you for answers- Moved by Cherry BuMicrosoft contingent staff Friday, September 21, 2018 1:45 AM move from wpf
Monday, September 3, 2018 6:22 AM
All replies
-
Hi TakeshiKitano,
According to your description, you want to allow multiple users to access database at the same time. When you update the data, the database will automatically lock this record.
In multi-user environment it’s possible that multiple users can update the same record at the same time causing confusion between users.
you will need to look into things like row locking, transactions, and isolation modes.
There are some articles about this, you can take a look:
https://www.codeproject.com/Articles/114262/6-ways-of-doing-locking-in-NET-Pessimistic-and-opt
If you use EF or ado.net, you can show your code here.
Best Regards,
Cherry
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Tuesday, September 4, 2018 2:38 AM -
I am very sorry ... excuse me for my english but I will try to describe my problem again (but maybe your answer is right)
1) - As it is mentioned above, program is stored in personal cloud in which are connected more computer (for example two)
2) - Both computer open that program at the same time and fill out some fields.
3) First one want to update old client's data - second one wants to insert new client's data
4) Both, of course, use another clientID ... BUT both use same fields from form
5) Both push at the same time button bntSave()
6) It happened that First PC updated old client with data that filled Second PC
Now I hope it is more clear ...
Thank you very much for your understanding
- Edited by TakeshiKitano Tuesday, September 4, 2018 10:29 AM
Tuesday, September 4, 2018 10:29 AM -
Then this sounds like there is something rather seriously wrong with your program, because it should not be possible for two different records to end up with the same data this way.
There is nothing inherently wrong with multiple PCs connecting to the same database and all updating and adding at the same time. This is what databases are for!
Generally the only things you need to consider are what to do if two people try to update exactly the same record at the same time. This is where you need to look at the things that Cherry Bu already mentioned in the post above.
If you have a situation where two PCs should be updating or adding two completely different records, but are somehow conflicting then, as I said, something is seriously wrong.
But this is going to be almost impossible to determine what without more information!
E.g. Perhaps a rough idea of the data schema, and any parts of relevant code you could supply.
Tuesday, September 4, 2018 11:02 AM -
OK, so sam problem -> two PC's -> not one update and one insert .... but both insert or both updateTuesday, September 4, 2018 11:56 AM
-
Hi TakeshiKitano,
Since this forum is discussing question about wpf, but your issue is related database, if you use sql server database, I suggest you can ask your question at Sql server forum or C# forum for professional help.
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?category=sqlserver
https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=csharpgeneral
Best Regards,
Cherry
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Thursday, September 13, 2018 6:34 AM