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

  • Home
  • SEARCH
  • 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 6172731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:26:37+00:00 2026-05-23T23:26:37+00:00

I am trying to record unique identifiers, so I cannot afford to have a

  • 0

I am trying to record unique identifiers, so I cannot afford to have a duplicate record of my ID’s

I am getting an error that looks like this when I try to update my SQL Server table called Clients.

Violation of PRIMARY KEY constraint ‘PK_clients’. Cannot insert
duplicate key in object ‘db_owner.clients’.

The code for this looks like so:

public void Subscribe(string clientID, Uri uri)
{
    clientsDBDataContext clientDB = new clientsDBDataContext();
    var client = new ServiceFairy.clientURI();
    client.clientID = clientID;
    client.uri = uri.ToString();
    clientDB.clientURIs.InsertOnSubmit(client);
    clientDB.SubmitChanges();
}            

Any Idea how I can go about fixing this, so I can update my rows, all I want to be able to do is when a row exists then only update the associated URI, and if it doesn’t exist to submit a new clientID + URI,

Thanks

John

  • 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-23T23:26:38+00:00Added an answer on May 23, 2026 at 11:26 pm

    What you want to do is first check for the existing record, and if it doesn’t exist, then add a new one. Your code will always attempt to add a new record. I’m assuming you’re using Linq2Sql (based on the InsertOnSubmit)?

    public void Subscribe(string clientID, Uri uri)
    {
        using(clientsDBDataContext clientDB = new clientsDBDataContext())
        {
            var existingClient = (from c in clientDB.clientURIs
                                  where c.clientID == clientID
                                  select c).SingleOrDefault();
    
            if(existingClient == null)
            {
                // This is a new record that needs to be added
                var client = new ServiceFairy.clientURI();
                client.clientID = clientID;
                client.uri = uri.ToString();
                clientDB.clientURIs.InsertOnSubmit(client);
            }
            else
            {
                // This is an existing record that needs to be updated
                existingClient.uri = uri.ToString();
            }
            clientDB.SubmitChanges();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to record using the iphones microphone: This is my code: NSArray
I'm trying to record audio this.recorder = new android.media.MediaRecorder(); this.recorder.setAudioSource(android.media.MediaRecorder.AudioSource.MIC); this.recorder.setOutputFormat(android.media.MediaRecorder.OutputFormat.DEFAULT); this.recorder.setAudioEncoder(android.media.MediaRecorder.AudioEncoder.DEFAULT); this.recorder.setOutputFile(pruebaAudioRecorder.mp4); **this.recorder.prepare();**
I have the scenario like this, My environment is .Net2.0, VS 2008, Web Application
Doctrine NOOB here, trying to figure out how to prevent a duplicate record in
I am trying to delete a record in my db based on the unique
I am trying to solve a unique problem. Thanks for any help with this.
I'm trying to create a trigger that will associate an unique random string to
I am trying to create a unique slug in Django so that I can
I'm getting the error in the title when trying to select a cookie value
I'm trying to get the top N records for each unique row of data

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.