.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Primary Key Constraint Violation on Update

Posted By:      Posted Date: August 30, 2010    Points: 0   Category :Sql Server
When UPDATING a single column (NOT the primary key column) of a transactionally replicated table, within MS SQL Server Management Studio, the replication monitor gives  Violation of PRIMARY KEY constraint 'PK_my_table. Cannot insert duplicate key in object 'my_table'. Statement Delivery is via the standard SCALL of dbo.sp_MSupd_my_table. The problem correlates with Statement Delivery of DELETE operations. That is, the problem exists if I specify "Do not replicate Delete Statements" and goes away if I specify standard behaviour for delete i.e a call on dbo.sp_MSdel_My_Table dbo.sp_MSupd_my_table does not appear to invoke deletion in any way and Im not updating the primary key value Any ideas Henrietta

View Complete Post

More Related Resource Links

Violation of PRIMARY KEY constraint 'PK_droughtDataTable_1'.

 Hello, I have a droughtDataTableAdapter which has the sqlINSERT INTO [droughtDataTable] ([StateName], [Moist], [Drought], [region], [district], [ID]) VALUES (@StateName, @Moist, @Drought, @region, @district, @ID) In the code I have the codeDataSet1TableAdapters.droughtDataTableAdapter k1 = new DataSet1TableAdapters.droughtDataTableAdapter(); for (int a = 0; a <= 254; a++) { k1.FillDrought( k[a][0], double.Parse(k[a][9]), double.Parse(k[a][12]), 1, k[a][1],a); }   However I got an error Violation of PRIMARY KEY constraint 'PK_droughtDataTable_1'. Cannot insert duplicate key in object 'dbo.droughtDataTable'. The question is that I don't have 'droughtDataTable_1', where is from for "_1"? The definition of the table droughtDataTable isStateName nchar(10) Moist float Drought float region smallint district varchar(50) ID int (Primary Key)   Thanks for help.

Violation of PRIMARY KEY constraint 'PK_User_Details'. Cannot insert duplicate key in object 'dbo

hi,i'm using sql server 2005 as backend for web development .In one of my database table User_Details, 'user_id' is the primary key ,and it is set to autoincrementing as follows.object count = objUser.countUid(); string count1 = Convert.ToString(count);            if (count1 == "0")            {                string uid5 = "U1";           objUser.addUser(string uid5);}else{               object uid = objUser.selectUid();                string usid = uid.ToString();                string uid2 = usid.Substring(1);                int uid3 = int.Parse(uid2);                uid3 += 1;                string uid4 = usid.Substring(0, 1);          

Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object


i am unable to insert values into my table when i am using primary key and foreign key in my tables i am sure that i have not voilated the constraints rules and its working well when i remove the constraints.....

Primary key violation on update statement for sqlserver2005 in asp.net


Violation of PRIMARY KEY constraint 'PK_StudentInf'. Cannot insert duplicate key in object 'dbo.StudentInf'.
The statement has been terminated.

the above message is appearing when i am upadating the record.

I am doing project  using asp.net 3.5 c#.net and sqlserver 2005,

i am executing sp for update using sqlhelper block, when i am updating record the above error occuring rarely(not for all records), if i update one record if get an error above second time it is updating nicely,

i am not able to finding the problem when and where it is occuring.

one thing here i am upadating primary column also like hallticket NO.

is there any problem if update primary column .

please tell me the solution it's urgent, and also it is on LIVE.

please give me solution as early as possible.

"Violation of PRIMARY KEY constraint . Cannot insert duplicate key in object ".

How this error could arise? I use data flow to insert rows from another server. I checked there is no duplicate key in primary key. thanks

Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object...


Hi all I set up transactional replication between a sql 2008 and sql 2005 server.  I have a table with an identiy column and a varchar field. I accidentally SET IDENTITY INSERT ON at the subscriber instead of the subscriber server and inserted a row. After that every row I inserted in the publisher has not be replicated to subscriber? I see this error message in the replication monitor?

Violation of PRIMARY KEY constraint 'PK__IdentTes__32149A135070F446'. Cannot insert duplicate key in object 'dbo.IdentTest'


I tried deleting the row at subscriber but still the same message?


Can't perform Create, Update or Delete operations on 'Table(outbox)' because it has no primary ke



I'm a beginner in asp.net and I have some problem inserting data into sql server 2005 with linq.


my code is : 


        Dim Result As New SMS.SendResult
        If Result.status = 0 Then
            Label1.Text = "Your Message Sent Successfuly"
            Dim db As New IGSSDataContext
            Dim out As New outbox With {.ClientID = intRandomNumber, .From = User.Identity.Name, .TO = TextBox1.TabIndex, _
            .Time = Now, .Message = Message}
            out.ID = (ID)
            TextBox1.Text = ""

Auto Binding Constraint doesn't update the UI

I needed a way to auto bind an activities inArgument to its parent activities delegateInArguments (property defined in an activity action). Picture dropping a WriteLine activity into an foreach<string> and having the foreach's argument automatically placed into the in argument of the writelines text property - binding it as it is dropped. I have created the constraint, and it works, including changing the binding to the parent or setting the property back to null if not in a parent.  My problem is that the UI doesn't reflect this.  It actually looks like it is doing nothing - I only know it works because it comes back correctly after a save and load of the workflow pattern. I'm guessing that I somehow need to refresh the model item? How do I refresh the model item from within a constraint? If it helps I have included the code for my constraint below, but note that my need is not as simple as the above example, so this does a couple of other things that don't make sense to this question. static Constraint CheckParent() { DelegateInArgument<GetTaskPermissionsActivity> element = new DelegateInArgument<GetTaskPermissionsActivity>(); DelegateInArgument<ValidationContext> context = new DelegateInArgument<ValidationContext>(); Variable<bool> result = new Variable<bool>(); Variable<

LINQ - Can't perform Create, Update or Delete operations on because it has no primary key.

Hi, not sure if I'm posting this thread in the right section. anyway, I''m trying to do the update/insert/delete using LINQ but the underlying table does not a primary key. The table consists of composite ket (e.g. fieldA & FieldB make a primary key). At the moment, I have LINQ complaning about not having a single primary key (not sure what LINQ does it - not making any sense at all). did anyone ever come across this issue and rectified it?  thanks

error '8007202f' Automation error A constraint violation occurred

I have an old COM+ object that we've used to create AD user accounts with information from our HR system.  This process has been broken since a recent upgrade, so I'm attempting to modify the object to point to a new DC and a new inforamtion store during mailbox creation.  After modifying the code I am unable to get an account to be crated and the following error appears: error '8007202f' Automation error A constraint violation occurred I am not a developer and I know that this is a long shot but if anyone has any insight into if this is an AD issue or one with VB 6, any help at all would be greatly appreciated.  I think this is the relevent code but again, I'm an admin not a developer:     thenewuser.SetInfo        thenewuser.SetPassword "NewBie!!!"     thenewuser.AccountDisabled = False        Set objMailbox = thenewuser         objMailbox.CreateMailbox "LDAP://MyDCCN=Mailbox Store (MyExchServer),CN=First Storage Group,CN=InformationStore,CN=MARLEY,CN=Servers,CN=MyStuff,CN=Administrative Groups,CN=MyStuff,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=MyDomain,DC=com"thenewuser.SetInfo Thanks in advance for any help.

Update records related to primary table in sql


HI All,

For example

I have 2 tables  Person and Person_Child.

In Person table i have columns

Id, PersonId,PersonName,PersonAdrress,PersonAge,RowId


rowid is identity


and in the person_child table--here parentrowid refers to parent table rowid and again rowid is identity here

Id, PersonId,PersonName,PersonAdrress,PersonAge,ParentRowid,RowId




I need to update the child table values as it is in parent tables where it is null.

I have to do for many tables.

Is there any way to do it dynamically.







MembershipUser.UnlockUser() throws exception: A constraint violation occurred. (Exception from HRESU



I'm having some problems getting code to work that'll re-enable a locked out account. Below is my code:

public bool ChangeAccountStatus(string username, bool enable)

                if (AzMan.CheckAccess(Operations["ChangeAccountStatus"], null) == false)
                    throw new SecurityException();

                MembershipUser user = Membership.GetUser(username);
                if (enable)
                    user.IsApproved = true;
                    if (user.IsLockedOut)
                    user.IsApproved = false;

                return enable;
            catch (Exception e)
                return !enable;

Enabling a disabled account works fine but when the account is locked out, I hit the user.UnlockUser() line and get the following exception:

Message "A constraint violation occurred. (Exception from HRESULT: 0x8007202F)"

StackTrace " at System.DirectoryServices.DirectoryEntry.CommitChanges()\r\n


with the transaction primary key violation error



i notice with in the transaction primary key violation error but all data never rollback,


use tempdb
drop table T1
create table T1(c1 int primary key, c2 varchar(5));
select * from T1
begin tran
insert into T1 select 1,'A'
insert into T1 select 2,'B'
insert into T1 select 2,'B'
insert into T1 select 3,'D'
commit tran
select * from T1


i need to know what is the sql server logic behind this?


Tharindu Dhaneenja

Tharindu Dhaneenja (http://spaces.msn.com/dhaneenja)

CreateDocument method in CMIS Object Service raising the Constraint Violation Exception


HI All,

Below are the code snippet for rasing the above exception like  "The operation violates a Repository- or Object-level constraint defined in the CMIS domain model. "


ObjectServicePortClient objectService = new TestCMISWinApp.ObjectService.ObjectServicePortClient("BasicHttpBinding_IObjectServicePort");

objectService.ClientCredentials.Windows.AllowNtlm =



primary key violation but want to resume next


I need to automate a script that import some data to a sql server 2005 table. The table is in a database of a web application of a vendor, but we need to do some data integration with it. The table   basically stores data for login for the portal and matches with our AD account. The login we use is our students' parents email address.it will be mapped with our AD account.What I need to do is import parent email address from our student information system, then compare with this table, do update and delete and insert.

The applcation table is like this with a primary key, in our case we use emailaddress of parents as MappedUsername, and it is also the same for Emailaddress field.

CREATE TABLE [dbo].[Mapper_UserMaps](

[MappedUsername] [nchar](255)  NOT NULL,

[AdUsername] [nchar](255)  NULL,

[EmailAddress] [nchar](255)  NULL,

[Data1] [varchar](510)   NULL,

[Data2] [varchar](510)   NULL,

[Data3] [varchar](510)   NULL,

[Gnum] [smallint]  NULL,



[MappedUsername] ASC




The problem is since some of our parents share email address, so for insert to the table, it caused primary key violation issue

violation of primary constraints

hi, i am trying to create a registration for a website, i used the CreateUserWizard, i decided then to create another table for storing 
some users' profile and found this article and it worked, the user is created and his profile gets stored in adifferent table similar to the article but i get a violation of primary
key constraint error. I searched about it and found out it is cause by
inserting duplicate data in the database. How do i solve
this?Please?Thank you so much.

Here's my code-behind for registration

Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles CreateUserWizard1.CreatedUser

        ' Get the UserId of the just-added user
        Dim User As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)

        Dim UserGUID As Guid = CType(User.ProviderUserKey, Guid)

        'Get Profile Data Entered by user in CUW control

        Dim FirstName As String = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("FirstName"), TextBox).Text
        Dim Middlenam

SQL DMO not scripting out primary/unique key constraint names, include indexes


I noticed that SQL DMO is not scripting out the primary key or unique key constraint names if there are created as part of CREATE TABLE statement.  Such constraints are scripted but constraint name is ommited.






Also SQL DMO is not scripting INCLUDE columns of the index. Is this by design that DMO doesn't support scripting for INCLUDED columns?

I am using sp_OAMethod for scripting out the definitions.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend