0

I am new to ASP.NET. I have a MVC web application accessing data from three tables in SQL Server. I have a requirement where if one user is editing data from one table then other users should not be allowed to edit any data. I have tried using a table in SQL Server with a flag for editing which set and reset based on user activity. But this doesn't seem to be reliable. Can someone suggest a better option to achieve this.

ajay
  • 11
  • 2
  • Do you need to lock the rows once they are read by the database? Or do you just need to prevent updates from overwriting others users updates without them being aware? – zep426 Jun 09 '22 at 18:33
  • As an example, if I am making changes to data from one table then other users should not be able to modify any of the tables. In my current solution I'm preventing the form to load for other users if one user is editing, by using a flag in db. – ajay Jun 10 '22 at 01:55
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jun 10 '22 at 08:34

1 Answers1

0

I believe there might be a better way to handle the whole situation you are in, but a suggestion would be that instead of a flag, you would have a datetime column that holds a lock expiration time. When reading the record, if the current time is prior to the expiration, the form wouldn't load. If the current time is after the expiration; read the data, load the form, and update the expiration in a serializable transaction. Finally, when a user completes there update set the expiration to the current time. This way, an error in updating the flag wouldn't hold a lock on the records indefinitely.

zep426
  • 179
  • 9