An unexpected error occurred while updating

Edit: Unfortunately I am no longer at liberty to reproduce the problem I was having here, because I stepped away from this project and don't remember if I eventually found a solution, if another developer fixed it, or if I worked around it. That's a side-effect of a feature called optimistic concurrency.

Not 100% sure how to turn it on/off in Entity Framework but basically what it's telling you is that between when you grabbed the data out of the database and when you saved your changes someone else has changed the data (Which meant when you went to save it 0 rows actually got updated).

From Paul Bellora's comment I had a similar issue but with a twist.

For me the issue was I didn't have the sql table setup correctly.

Luckily in may case the trigger functionality was incorrect, but I guess it could be a valid operation that should somehow be handled in code. To expand on the comment by @jahu, I had to get an actual id of the newly inserted item to be returned from my trigger and the column name has to match the trigger table's identity column (in my case, actually a view so it didn't have an identity of its own but I had tricked the edmx into believing it did).

My trigger was doing an insert into a separate table, so I just added this last line to my trigger: In my case I was doing a delete operation on entities in a child collection but there was a trigger on delete for one of the child entities that caused another of the child entities to be deleted.

In SQL terms, their clause contains the original value of every field in the row, and if 0 rows are affected it knows something's gone wrong.

The idea behind it is that you won't end up overwriting a change that your application didn't know has happened - it's basically a little safety measure thrown in by . If it's consistent, odds are it's happening within your own logic (EG: You're actually updating the data yourself in another method in-between the select and the update), but it could be simply a race condition between two applications.

I am binding to a custom grid control with an Entity Data Source so I'm not sure exactly what's happening behind the scenes, but I don't have any extra code of my own that is modifying the tables. I think you can on a per-column basis in your entity model (It's in the properties window), but the thing is that'll just prevent you seeing the error and it'll still not update anything.I tried looking up in traces and run SQL profiler to try and grab the error but to no avail.Ultimately it turned out that the view had a few columns coming in from antoher entity.At the time you are saving the object to db, you need the previous value of the Row Version submit to the db along with the object for the concurrency check.You make silly mistakes when you need things faster!

Search for an unexpected error occurred while updating:

an unexpected error occurred while updating-52an unexpected error occurred while updating-54an unexpected error occurred while updating-38

Leave a Reply

Your email address will not be published. Required fields are marked *

One thought on “an unexpected error occurred while updating”