Wrox Programmer Forums
|
BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio
This is the forum to discuss the Wrox book ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solution by Vincent Varallo; ISBN: 9780470396865
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 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 April 8th, 2009, 07:10 PM
Authorized User
 
Join Date: Mar 2009
Posts: 79
Thanks: 4
Thanked 4 Times in 4 Posts
Default Primary Key Fields

Hi all,

It appears that I am near the end of my first applied framework application.
Everything appears to be working with no errors during compile.

When testing I was able to pull up the form and input information, all of the validation works as it should and the record saved.

The second record would not save because it is trying to pass ID = 0 to ensure that it is a new record. However I do not fully understand where does it increment the primary key information. I checked that Identity Specification > Identity Increment was turned on but now I get the following error when saving from the HRPaidTimeOff.designer.cs

Code:
Cannot insert explicit value for identity column in table 'AETransfer' when IDENTITY_INSERT is set to OFF.
This appears to be a SQL related issue but I am not so sure.
I looked through the book's index to see if I could find IDENTITY_INSERT anywhere but it is not listed. Im flying blind on this one, I could do a dirty hack to get around it, but I would like to have my first implementation of the the framework pure incase I have to reference it (which would be often)


Thanks
 
Old April 9th, 2009, 02:14 AM
Authorized User
 
Join Date: Apr 2009
Posts: 41
Thanks: 1
Thanked 2 Times in 2 Posts
Default

Are you passing in an identity number on the insert? Based on the error, it sounds like you're passing in a value for the identity column.

For example, you have a table with 3 columns, the first one being an identity column.

IDENTITY_INSERT is set to off (the default value, I'm assuming).

Doing this:

INSERT INTO table(column1, column2, column3)
VALUES (1, 2, 3)

will generate that error, because SQL Server is expecting to generate the value in column 1 on the insert.

Instead, you'd want to do:

INSERT INTO table(column2, column3)
VALUES (2, 3)

SQL Server would populate column 1 with the next available identity value for that table.

The other option would be to set IDENTITY_INSERT to ON, but that would defeat the purpose of having an identity column, IMO. The only reason I've seen to use IDENTITY_INSERT is when you're preloading rows into a table during installation/setup of an application (though there could be other valid reasons).

If you're using the code straight from the book, all of the tables use the same format for the identity column name - <tablename>Id. I.e., ENTUserAccountId, ENTRoleId, ENTMenuItemId, etc.

Tim
 
Old April 9th, 2009, 02:19 PM
Authorized User
 
Join Date: Mar 2009
Posts: 79
Thanks: 4
Thanked 4 Times in 4 Posts
Default

Tim thanks for your input. Based on what you posted that got me thinking about my Stored Procedures for Insert into my table.

Sure enough I found that the Stored Procedure was passing in the Id field. Removed that and now Im working. So it was SQL related so to speak, I will need to correct that in the Code Generator at a later date.

Thanks for the insight.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Foreign key not updating with Primary key xavier1945 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2007 09:48 PM
FOREIGN KEY and PRIMARY KEY Constraints junemo Oracle 10 June 15th, 2004 01:00 AM
Mulitple fields primary key ksa266 Access VBA 1 December 15th, 2003 10:13 AM





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