.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

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

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :ASP.Net

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.....

View Complete Post

More Related Resource Links

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 ".

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?


Primary Key Constraint Violation on Update

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

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.

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 =



Cannot insert duplicate key row in object 'dbo.catalog'

Either I did a dumb thing, or SSRS 2005 is doing a dumb thing (or both?). Or maybe it's a SharePoint integration issue...

Here's what happened:

1. I published a report to the report library (we're in SharePoint integration mode)
2. In SharePoint, went to the new report and did "Edit Properties", and changed the report name in the Name field to a nicer, user-friendly name
3. Back to BIDS, I make a change to this same report and deploy again.
4. Now back in SharePoint, I see that there are two reports - the original one that I renamed in step 2, and this new one that I just deployed 
5. Now I delete the original one (with the nice new name), and rename this new one to that same exact name
6. When execute the report now, it won't run -- I get the following error:

Report Server has encountered a SharePoint error. (rsSharePointError)
Cannot insert duplicate key row in object 'dbo.catalog' with unique index 'IX_Catalog'. The statement has been terminated.
For more information about this error navigate to the report server on the local server machine, or enable remote errors 

The problem i

Cannot insert duplicate key row in object 'Table' with unique index 'Column_Id' Problem


All, We have a User where there is an Access Application installed. Every Day he enters some Account Numbers in it. This Access application is hooked to SQL Server 2008 which updates a table in SQL Server. Now last 2 weeks user had some Connection Issues so he did not enter any Account Numbers in the Access application instead he just noted them on a Excel sheet.

Now I did not want him to insert manually, so I took that Excel sheet, loaded account numbers in a Temp table and tried to insert all the Missing Account Numbers in the Main table. But it failed with the following error: Note: Account_No has a Unique Non Clustered Index on it and it is not a Primary key also. How can I insert them? (There are no duplicate account numbers as well that I am trying to insert its all Unique Accout Numbers)

Msg 2601, Level 14, State 1, Line 1
Cannot insert duplicate key row in object 'dbo.Table_Name' with unique index 'Accoutn_No'.
The statement has been terminated.


Insert permission was denied on Object '', database '', schema ''

i have a senario where in i am trying to insert data into a Database , i end up getting the above error 'Insert permission was denied on Object '', database '', schema '''.We have a DB which has all Storeprocedures and 90% of the tables . the remaining 10% of the tables are in a different database.I am having trouble inserting data into the second database.The storeprocedure is executed as a user who has permission on the DB and tables.Also the storeprocedure is given permission to a role in which the user is a member . The same role doesnt exists in the 2nd Database.I am able to do all DB operations in one environment . i am unable to do the same in the others.

Duplicate constraint name

I have a 3.5 SDF file which contains duplicate FK constraint names. Is this a known bug? CONSTRAINT_TABLE_NAME CONSTRAINT_NAME UNIQUE_CONSTRAINT_TABLE_NAME UNIQUE_CONSTRAINT_NAME UPDATE_RULE DELETE_RULE Users_Log_Communications Users Users PK_Users Users_Log_Sensors Users Users PK_Users  From BOL: constraint_name The name of a constraint. The constraint_name is optional and must be unique within a database. If a constraint_name is not specified, SQL Server Compact 3.5 generates a constraint name. CASCADE CASCADE         Visit my SQL Compact blog - http://erikej.blogspot.com - Please mark as answer, if this was it.CASCADE CASCADE

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.

Formview check for duplicate value before insert

I've looked at some posts on here but I keep getting errors.  I am just trying to see if an email address exists already before the insert and if it does, have a label display that message to the user. From what I read so far, it looks like I could do a query in the ItemInserting event.  I just need help on the code.  Thanks in advance for any help.. Here is the Code Behind.....where I assume I can do the duplicate check in the ItemInserting event... Protected Sub duplicatecheck(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles FormView1.ItemInsertingEnd   End Sub     Here is the formview page...   <%@ Page Language="VB" AutoEventWireup="false" CodeFile="signup.aspx.vb" Inherits="signup" %> <! < <DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">html xmlns="http://www.w3.org/1999/xhtml">head runat="server">   </ <<title></title>head>body>  <form id="form1" runat="server">  <div>      <asp:FormView ID="FormView1" runat="server" DataKeyNames="ID" DataSourceID="SqlDataSource2" Def

Parent and child object insert through dataadapter

Hi,I have Parent(order)and child(Orderdetail) object how to  insert through dataadapter.Update() method in single shot.

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)

Browser refresh and duplicate insert,...again

Hi Guys,

I have "duplicate ID insertion when user refreshes page" problem.

I looked and looked but can't find a quick fix (response.redirect to the page again is just
not an option,...want to keep the UI without flickering controls ..ajax used here) nor do I
want to add new columsn to the database.

page.IsPostback does not solve the issue either, since it is not a postback we are dealing with here.

I just wonder how the brwoser "refresh" triggers my button1.click sub in the first place - since
the button is not clicked. I guess the http header somehow has the click event in it.
Is there a, easy (vb.net) way to detect "refresh" and avoid the instertion.

i read the following "One way would be to use AJAX and call a web service / page method to handle the insert. "
Any suggestions how that would work?

Special Insert Constraint Rule for Two Columns


I have a SQL Server 2000 table with 7 columns and would like to add a constraint that prevents a row being added with the same value for both Col2 and Col3.

So, for example, if Col2 = 205 and Col3 = 5, then the constraint should prevent inserting another row with the values for Col2 = 205 and Col3 = 5.

The following is an example of what I would like to prevent:

Col1     Col2     Col3    Col4    Col5    Col6

1          205       5        1          1         1

2          205       5        0          0         0

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