1

My program is writing records to a db table. So far, it has written about 58 new records to this table. All of a sudden, I get an error message saying "Row not found or changed." Which is odd, because I'm inserting a new record, not trying to find one or update an existing one. Here's the small bit of code that I'm using to create an object and then insert to the table:

// create new comment object
var comment = new Comment
                  {
                      TableName = "Circuit",
                      TableKey = circuitId,
                      Text = remarks,
                      CreatedOn = DateTime.Now,
                      CreatedByName = "loadCC03Circuits",
                      CreatedByUupic = "000000000"
                  };

cimsContext.Comments.InsertOnSubmit(comment);
cimsContext.SubmitChanges();

I'm not quite sure what to do, at this point. Each field has a value, there are no nulls. And, as I said, 58 records have already been written out by this very same bit of code before this happens so, other than the data being off (which, according to the field values in my debugger session, are not) I'm not quite sure what else to check. Any advice?

EDIT: I added an answer below that made this problem go away. But, I'm not sure why this solution worked.

RobSiklos
  • 8,348
  • 5
  • 47
  • 77
Kevin
  • 4,798
  • 19
  • 73
  • 120
  • Did you look at this question? http://stackoverflow.com/questions/8851482/linq-row-not-found-or-changed – Chizzle Sep 08 '15 at 19:30
  • I did. That problem is happening when they're reading a record from the table, modifying it, then updating the record. In my case, I'm just trying to insert a new record. That's what's confusing me: It says "Row not found or changed..." but I'm not looking for a row or changing one; I'm inserting a new one. – Kevin Sep 08 '15 at 19:31
  • You see the second answer about the nullable column not matching the model? Could be that, just a shot – Chizzle Sep 08 '15 at 19:32
  • @3dd Hmm, you may be onto something. That table DOES have a trigger on it. I need to investigate this. I'm not the author of the trigger and this was recently added by another developer. Thanks! EDIT: I was wrong. This particular table, Comments, doesn't have a trigger at all. I was thinking of another table. – Kevin Sep 08 '15 at 19:33
  • @Chizzle I did not read the second answer. I shall do so, now, and see if there is anything there to help. Thank you! – Kevin Sep 08 '15 at 19:33
  • @Chizzle Well, I could find nothing else to helped me on that link. My model is exactly as the db schema, and I'm not updating an existing record, just trying to insert a new one. I do you thank you for that link, though. I learned a few new things reading the answers there. – Kevin Sep 08 '15 at 19:38
  • It just seems strange to me that the program can run smoothly along and insert 58 records and then, boom!, it blows up with this exception. And every one of the fields have a valid value in them. The error message seems to be indicating a problem with looking for a particular row and trying to update that. Since I'm inserting a new record, I can't fathom what this error message is trying to tell me. – Kevin Sep 08 '15 at 19:40

1 Answers1

1

I found a solution, but not the "answer". The solution, in this case, was to make a variable that contained the DateTime.Now value:

var dateNow = DateTime.Now;

And I changed the affected line of code to look like this:

CreatedOn = dateNow,

Wonders of wonders, I no longer received the error. I'm not sure why this fixed the problem, I only tried this on a suggestion from a co-worker. He theorizes that the sandbox database that I'm working is sluggish and could be affecting the DateTime.Now function. Regardless, this made that issue go away. I wish I had a definitive answer, though. I hate making a problem go away when I don't understand why the solution worked.

Kevin
  • 4,798
  • 19
  • 73
  • 120