Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 572453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:36:52+00:00 2026-05-13T13:36:52+00:00

I have some linq2sql stuff which updates some rows. Then when I submit I

  • 0

I have some linq2sql stuff which updates some rows.
Then when I submit I do this:

try
{
    database.SubmitChanges();
}
catch (ChangeConflictException)
{
    database.ChangeConflicts.ResolveAll(RefreshMode.KeepChanges);
    database.SubmitChanges();
}

Now the second submit(the one in the catch) is throwing yet again a ChangeConflictException

How is that possible? And if it is possible. How would one need to do the query? (I can not put yet another try/catch around that one? When would I stop?)

I want only the changed values to be put in the database.

EDIT:
let me rephrase the intent of the question: When I say ‘ResolveALL(keepchanges)’, I would think that I say: “I don’t care..just use my values”. Instead, it throws yet again the same exception.

I was surprised by this behaviour since the examples on MSDN don’t have a second try catch around the second SubmitChanges

So how many times can these exceptions be thrown(As many times as there are columns?), and can I avoid them altogether somehow (after saying ResolveAll)?

EDIT:
Last edit before I start the bounty:

I’ve made it into a neat loop as suggested by 1 of the commenters. But it doesn’t matter how many times I retry. The moment it starts throwing exceptions, it will never do it without an exception! So either it works the first time, or it won’t work at all.

Now my linq update has some 20 or 50 rows in it which need updating (I work with batches to speed things up).
Is every resolveall only fixing one issue in 1 column ion 1 row? or is it smart enough to fix everything it encountered?

To recap: the values I just changed (only 1 or 2 columns) are the ones which need to go into the database no matter what. How can I do this using linq (or should I really resort to opening an SqlConnection for this? (If so why Linq in the first place?)

My code up till now:

 int retry;
 for (retry = 0; retry < 10; retry++)
 {
      try
      {
           database.SubmitChanges();
           //submit succeeded... break loop
           break;
      }
      catch (ChangeConflictException)
      {
           database.ChangeConflicts.ResolveAll(RefreshMode.KeepChanges);

           if (retry > 0)
           {
                Thread.Sleep(retry * 10);  //introduce some wait, to see if this helps
           }
      }

EDIT: Found it!

Thanks to the link to the blog in the accepted answer I now cycle through all the conflicts and log them to see what is causing this.

And I’m glad I did, since as it turned out that one of the DB fields contains a trigger which updates something else in certain conditions. So I could resolve as much as I liked, every time the trigger would fire again, causing the next conflict.

This trigger obviously I was not aware off, since my DB admin put it in place there to track something or the other. Triggers can be a great tool, but if you are not aware of them they can cause major headaches!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:36:53+00:00Added an answer on May 13, 2026 at 1:36 pm

    It may not be picking up on all your conflicts when you call SubmitChanges() (and therefore not resolving them all), because the default behavior is to stop when it reaches the first one.

    Try changing

    database.SubmitChanges();
    

    to

    database.SubmitChanges(ConflictMode.ContinueOnConflict);
    

    See http://arun-ts.blogspot.com/2009/08/linq-to-sql-concurrency-conflicts.html for more info. He also nests two levels of try/catch in his code sample for ResolveAll(), so the second time SubmitChanges() is tried, he’s able to log any exception before exiting. That seems like a reasonable model to follow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 351k
  • Answers 351k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There is no good automated way to do this. If… May 14, 2026 at 7:14 am
  • Editorial Team
    Editorial Team added an answer You use "think times" to control the wait time between… May 14, 2026 at 7:14 am
  • Editorial Team
    Editorial Team added an answer Have you check the file permissions for the images? maybe… May 14, 2026 at 7:14 am

Related Questions

I have an ASP.net Web Site Project (.net 3.5). Currently all of the non-code
There are a few should I chose this or that questions on SO and
so I'm using LinQ2SQL quite heavily in my current application, and although I have
I have a Users table, Events table, and a mapping of UserEvents. In some
Lets say I have this table: PetID Name Age Weight How can I in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.