Tuesday 30 October 2012

Row not found or changed

Today whilst working with what had been a stable piece of LINQ for some weeks, I had to use the data connection in a separate application. I thought this would be straightforward as I'd been using it in its current application for quite some time.

Upon trying to update a row, to merely save a string value, I received the "Row not found or changed" error.

Doing the usual Googling and finding many many people complaining about this on StackOverflow, I tried all the suggestions of changing the datefield in the table to never complain about it updating, checking that no count wasn't enabled for the database, re-dragging the table into the DBML to update it etc, but nothing seemed to work.

In final desperation, I just happened to be sat with SQL Management Studio open and that particular table expanded so I could see the fields, and also the dbml open and the what appeared to in the end be the offending field, properties open. I noticed that even though I had re-dragged the table to the DBML that the specification for nullable was different. On the server null was valid, but in the DBML it was Varchar(500) NOT NULL.

So there we have it. The row couldn't update because LINQ interpreted the definition it had to be different to the database.

And the strangest thing? I was trying to update it so that it wasn't null, and in the database there is a default value for it.

If you've come to brick wall with this, I hope this helps you too!

No comments:

Post a Comment