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 6192491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:57:08+00:00 2026-05-24T02:57:08+00:00

It was difficult to choose correct title, but here is the problem: I’ve an

  • 0

It was difficult to choose correct title, but here is the problem:

I’ve an application with simple logic, that gets data from TFS, iterates over “items” and updates local DB with these “items”. Here is a code snippet for updating the row:

using (ResultDBDataContext local_db= new ResultDBDataContext())
{
DBTestResult dbRes = local_db.DBTestResults.getByPrimaryKey(args_supplied);
if (dbRes == null) {
  dbRes = new DBTestResult(){//set properties}
  local_db.DBTestResults.InsertOnSubmit(dbRes);
}
else{
  dbRes.isDirty = true;
  dbRes.otherPropertis = set_to_some_values;
}
local_db.SubmitChanges();
}

This is working in Windows Console program (imported >100K rows like this), which proves that logic is correct. But when I put same logic to Windows Service (against same data), after a while (<2K rows) I get an SQL exception saying “can’t insert duplicate key into the table”. Note that I do SubmitChanges() after updating/inserting each row

I think this is somehow related on the followings, but not able to find out the reasons:

  • How Windows Services handle DB connectios. (Do they pool? Do they cache data? etc.)
  • Linq2SQL Dataconext handling it’s update objects. (What properties of Linq2SQL Datacontext make it behave differently under Windows Services?)

Any ideas/suggestions/links/tutorials/articles on how to resolve this issue or on finding out more information about the problem are greatly welcome.

Thanks.

Update: The data coming from TFS, may violate the database’s primary key constraint – but since I’m inserting/updating one row at a time and committing changes, the last entry for the same primary key will reside in database.

  • 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-24T02:57:09+00:00Added an answer on May 24, 2026 at 2:57 am

    Any ideas/suggestions/links/tutorials/articles on how to resolve this issue or on finding out more information about the problem are greatly welcome.

    This sounds to me like it’s not a problem with the service side of the code.

    I think you need to log/inspect this error behaviour further – just try logging which primary key(s) this is occurring for – it may be that you’ll notice some error in your getByPrimaryKey implementation that way.

    Also check that your service is single threaded – i.e. that there can’t be two instances executing simultaneously – that could certainly lead to an error.

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

Sidebar

Related Questions

You would have thought that tere is a simple solution to this but there
This is a difficult and open-ended question I know, but I thought I'd throw
It's surprising how difficult it is to find a simple, concise answer to this
Sometimes it's difficult to describe some of the things that us programmers may think
What's so difficult about the subject that algorithm designers are having a hard time
Basically I need to choose one so that, I can get familiar with it
NetBeans used to do that but with the deprecation of Woodstock (rather merging with
We need to choose the reporting engine for our ASP.NET application. The main functional
I have a web-based application that notifies users of activity on the site via
I am trying to build a data table structure that will best support the

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.