-2

I'm developing a WPF application for multiple user work on the same local network using MS SQL Server. I want to prevent users from editing the same record at the same time.

Example: Let us say the User1 modifying record number 5, If User2 Try to view or modify record 5 the application will return warning message to the User 2.

Any Idea?

Thanks in advance

Abdulsalam Elsharif
  • 4,773
  • 7
  • 32
  • 66
  • Store that in the database, then look it up. – SLaks Jul 09 '17 at 14:19
  • How do you know he is 'modifying ' a record? MS SQL handles concurrency control by itself. No quite sure why you are trying to do it – Suraj S Jul 09 '17 at 14:20
  • Clear your idea please – Abdulsalam Elsharif Jul 09 '17 at 14:20
  • you should use Transitions to manage the update process. Because at time you have multiple operation are running. this is link to be your answer.https://dev.mysql.com/doc/refman/5.7/en/commit.html – Pratius Dubey Jul 09 '17 at 14:23
  • A common pattern that is easy to implement is "optimistic concurrency". If you make sure there is a RowVersion or TimeStamp property on the object then you can check in the UPDATE query if it is different than when the SELECT was done. If so you can warn the user at that point and reload the new data or allow them to overwrite the last saved data. – Crowcoder Jul 09 '17 at 14:28

1 Answers1

2

You can create another table called ModifyCheck, just containing the record_id and user_id. When a user is modifying a record, it should insert an entry into ModifyCheck. When the user finish modifying that record, you can either delete that entry or update it to reflect completed. Can store timestamp too.

So when another user tries to view / modify, you need to do a check with ModifyCheck table to see if that specific record is being modified right now.

licitdev
  • 319
  • 2
  • 9
  • What happen if the computer shutdown while the user modifying? In this case no one can edit this recode. – Abdulsalam Elsharif Jul 09 '17 at 14:25
  • Eg: User1 is now editing Record1, stored in ModifyCheck. If computer dies, it does not matter. So long as you still allow User1 to modify it and finish the process. So you will need to do a check to allow same User to access modify screen, denying other users. – licitdev Jul 09 '17 at 14:27
  • This is work, But I'm facing this issue if you can help https://stackoverflow.com/questions/45131582/save-changes-for-one-object-in-wpf – Abdulsalam Elsharif Jul 16 '17 at 17:42