1

We have an edit form that only allows one user to edit a form at a time. The form is quite large and has quite a bit of Knockout.js code in it and this code intercepts the Submit button click to do validation, then if everything is fine it submits the form.

Nothing has changed on the server side or view side, yet just in the last few days we are having a large amount of OptimisticConcurrency errors being logged.

Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions.

The only other correlation is that some users are complaining about the site running slow. I was hoping someone may have a guess as to what is causing this? It is probably affecting less than 1% of our forms but this still causes a lot of inconvenience. It is a MVC 5 site on a load balanced server.

Aside from what may be causing this, is there some other idea of what I should do to solve the problem, like switching to a client wins concurrency exception? These are medical records so any data loss could be detrimental.

Update

From the comments, here is the code that runs when the submit button is pressed.

self.saveClick = function () {
    validationTests();
    if (self.validationError()) {
        return false;
    } else {
        return true;
    }
}

So that wouldn't disable the button from being pressed multiple times, would it? This may be the problem, now that the site is running slow.

Garrett Fogerlie
  • 4,450
  • 3
  • 37
  • 56
  • which isolation level your sql server is running? – TheGameiswar Mar 18 '16 at 08:43
  • @TheGameiswar Read committed. – Garrett Fogerlie Mar 18 '16 at 09:25
  • Does your logging not say who was editing what record? ask the users, it seems unlikely that two people would be on the same medical record but they might have changed working patterns? – dibs487 Mar 18 '16 at 09:38
  • @dibs487 That's what's strange, it is all the same users per form, here is an example http://imgur.com/38sn70y I check each entry and they are all the same form for that user. Same forms for the other users too. My only guess is that there must be some glitch that is sending multiple submits almost simultaneously? I don't know how that would happen or if that would even cause this problem though. Like I said in my post, the only other complaint we've received lately is that the site is running slow, I don't know if there is any relation. – Garrett Fogerlie Mar 18 '16 at 09:47
  • site running slow, so they're not sure they pressed submit so they press it again? are you disabling the submit button once clicked? – dibs487 Mar 18 '16 at 09:57
  • @dibs487 You may be onto something, look at my updated question at the bottom. If I hide the submit button or change it to a wait, that may fix the problem. Or at least prevent multiple submits, if that is causing the problem. Am I correct? And thank you, BTW. – Garrett Fogerlie Mar 18 '16 at 10:06
  • got to be worth a try, plenty of examples on SO for how to disable a submit on click, remember to re-enable if you fail validation. I had to do this when we had a user that double-clicked on any button you gave her. – dibs487 Mar 18 '16 at 10:36
  • @dibs487 Well I implemented a solution, if it works then that was the problem or it was just some strange event that stopped happening. Either way I think you should submit it as an answer and if I notice the problem has stopped I'll select it as correct. At the very least you get a plus one. Thanks – Garrett Fogerlie Mar 18 '16 at 11:56

1 Answers1

1

As you're getting multiple submits from the same user it's probably worth ensuring that your submit button is disabled on a click. Here's a question with an example of how to do this

Disable submit button on form submit

worth noting that as you're doing lots of validation then you need to re-enable the button if it fails validation.

Community
  • 1
  • 1
dibs487
  • 1,294
  • 4
  • 21
  • 36
  • This seems to have solved the issue. I used my own method for disabling and even enabling the Submit button if the page just sits there. Thanks! And welcome to StackOverflow. – Garrett Fogerlie Mar 19 '16 at 10:37