Search code examples
c#asp.net-mvclinq-to-sqlhttphandlerdatacontext

How do I stop Ajax calls to SubmitChanges on DataContext from causing errors?


I have a .NET MVC application in which an HttpHandler logs requests in a database via Linq to Sql. 50% of the time, when I click a link to make an ajax request, the SubmitChanges() of the DataContext throws an error "The operation cannot be performed during a call to SubmitChanges".

This is caused by the line "System.Data.Linq.DataContext.CheckNotInSubmitChanges()". It appears that the cause for the error is that the DataContext is already in the process of another SubmitChanges() call. However, there is only one call for the request that is being generated.

I've been messing with this for about 12 hours and am pretty close to just writing old school SQL statements, because this is very frustrating. I sincerely appreciate any help you all can offer.


Solution

  • Here are some articles i wish can help to you.

    Linq to SQL DataContext Lifetime Management

    Object States and Change-Tracking

    Linq to SQL DataContext Lifetime Management Issue