views:

175

answers:

2
System.Data.Linq.ChangeConflictException: 2 of X updates failed.
  at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
  at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
  at PROJECT.Controllers.HomeController.ClickProc(Int32 id, String code, String n)

This is what I get very often. This action is done thousands of times a day, and I get this exception about once every 5 seconds. From what I understand it happens when something changes in the database in the period between creating DataContext and updating it. Am I right?

How can I fix it?

Update

I just debugged the error and found the following:

Table name: dbo.Stats
current value: 9852039
original value: 9852038
database value: 9852039

The Stats table is updated constantly. So how can I still make LINQ save the changes. With "classical" SQL Server access through SqlDataCommand I never had problems like that.

A: 

I just debugged the error and found the following:

Table name: dbo.Stats
current value: 9852039
original value: 9852038
database value: 9852039

The Stats table is updated constantly. So how can I still make LINQ save the changes. With "classical" MS SQL access through SqlDataCommand I never had problems like that.

Alex
+4  A: 

This is due to optimistic concurrency. You can change this behavior but understand what it does before you do it.

http://blogs.msdn.com/matt/archive/2008/05/22/into-to-linq-to-sql-optimistic-concurrency.aspx

Raj Kaimal