Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 25th, 2007, 09:14 AM
Authorized User
 
Join Date: Oct 2006
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default Violation of primary key

I'm getting this common error

Server Error in '/FireworksPermitApp' Application.
--------------------------------------------------------------------------------

Violation of PRIMARY KEY constraint 'PK_tblTempOnlineFWUsers'. Cannot insert duplicate key in object 'tblTempOnlineFWUsers'. The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK_tblTempOnlineFWUsers'. Cannot insert duplicate key in object 'tblTempOnlineFWUsers'. The statement has been terminated.

Source Error:

The things is, when I check that particular table, the ID is being created and entered. So I really don't know where this error is spinning from. I was thinking that my primary key, which vchUserId, was being duplicated but it's not. So I don't understand. Can someone please help me?

 
Old May 25th, 2007, 09:21 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Is your PK an auto inc value?? If it is, are you trying to explicitly insert a value into that column? If you are, don't, as this can cause the type of error you are seeing.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 25th, 2007, 10:33 AM
Authorized User
 
Join Date: Oct 2006
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No, it's not set to auto inc.

 
Old May 25th, 2007, 10:51 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ok, so you are trying to insert a value manually into the PK field. If you are certain that you are not duplicating the ID in your table, this might be a relationship problem with another table; while the pk might be unique in your source table it might conflict else where.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 31st, 2007, 10:19 AM
Authorized User
 
Join Date: Oct 2006
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You're right. For some reason when I click submit, it tries to run the same routine twice. Because when I take the primary key off, it goes thru without the error and enters in the same UserID twice. But with the primary key it throws up that error. I've came to the conclusion that it's running the routine to enter the ID twice. So now I have to figure out why it's doing that.

I don't know if I mention it before but, What I'm thinking is that when I click submit, it enters the userID. Instead of going redirecting it to the wanted page, I get this website certificate page telling me that that it may not be safe I'm thinking when I click continue, it tries to enter that same userID again and throws that error.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Violation of PRIMARY KEY constraint??? twyce C# 1 September 9th, 2008 01:23 AM
Foreign key not updating with Primary key xavier1945 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2007 09:48 PM
Primary Key Violation error code hasanali00 BOOK: ASP.NET Website Programming Problem-Design-Solution 1 April 19th, 2005 07:41 PM
primary key violation muralikeane Classic ASP Databases 8 May 21st, 2004 09:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.