 |
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
 | This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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
|
|
|
|
|

July 28th, 2009, 04:26 PM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 70
Thanks: 18
Thanked 1 Time in 1 Post
|
|
Page 457 - 'Foreign Key' problem
After I enter the details in ManagePhotoAlbum.aspx, the details go into the PhotoAlbum table in the database (I've checked using DatabaseExplorer). However, when I click Insert, instead of getting the situation as in Figure 13-6, I get a 'foreign key' problem - see below. I can see no error in the PhotoAlbum table, and the relationship diagram appears correct when compared with that in the downloaded source file.
Any suggestions about this error?
Server Error in '/Site' Application.
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Picture_PhotoAlbum". The conflict occurred in database "C:\BEGASPNET\SITE\APP_DATA\PLANETWROX.MDF", table "dbo.PhotoAlbum", column 'Id'.
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: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Picture_PhotoAlbum". The conflict occurred in database "C:\BEGASPNET\SITE\APP_DATA\PLANETWROX.MDF", table "dbo.PhotoAlbum", column 'Id'.
The statement has been terminated.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
Code:
[SqlException (0x80131904): The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Picture_PhotoAlbum". The conflict occurred in database "C:\BEGASPNET\SITE\APP_DATA\PLANETWROX.MDF", table "dbo.PhotoAlbum", column 'Id'.
The statement has been terminated.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1948826
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4844747
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
System.Data.SqlClient.SqlDataReader.get_MetaData() +83
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
System.Data.Common.DbCommand.ExecuteReader() +12
System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult) +975
System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries) +113
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +344
System.Data.Linq.StandardChangeDirector.DynamicInsert(TrackedObject item) +136
System.Data.Linq.StandardChangeDirector.Insert(TrackedObject item) +202
System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode) +236
System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode) +331
System.Data.Linq.DataContext.SubmitChanges() +19
System.Web.UI.WebControls.LinqToSqlWrapper.SubmitChanges(DataContext dataContext) +9
System.Web.UI.WebControls.LinqDataSourceView.InsertDataObject(Object dataContext, Object table, Object newDataObject) +83
System.Web.UI.WebControls.LinqDataSourceView.ExecuteInsert(IDictionary values) +448
System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +86
System.Web.UI.WebControls.ListView.HandleInsert(ListViewItem item, Boolean causesValidation) +277
System.Web.UI.WebControls.ListView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +652
System.Web.UI.WebControls.ListView.OnBubbleEvent(Object source, EventArgs e) +233
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.ListViewItem.OnBubbleEvent(Object source, EventArgs e) +112
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.4028
|
|

July 28th, 2009, 05:06 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Take a look here:
Chapter 13 Error
or here
SQL Error, p. 456, step 16
The first post describes a case where the database diagram *looks* right, but is actually joining the tables on incorrect columns.
The error in the other post was caused by the fact an incorrect album ID was retrieved from the query string.
Hope this helps,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

July 28th, 2009, 07:01 PM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 70
Thanks: 18
Thanked 1 Time in 1 Post
|
|
Ha! It was an almost identical fault to the second one.
Code:
"ManagePhotoAlbum.aspx?PhotoAlbunId={0}"
instead of
Code:
"ManagePhotoAlbum.aspx?PhotoAlbumId={0}"
Many thanks.
|
|

April 7th, 2011, 12:44 PM
|
|
Registered User
|
|
Join Date: Mar 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Capter 13 The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Picture
After spending 3 hours fiddling about with my databasez Fk_xyz_xyz constraint, deleting rebuilding relations in tables and banging my head on the desk I found the 2nd suggested solution to work for me.
Was just the wrong name in the query!
Wish would have looked into it before!
This was the error.
"ManageDocuments.aspx?DocumentId={0}"
instead of:
"ManageDocuments.aspx?DocumentAlbumId={0}"
Thanks Imar.
Waqqas.
|
|
 |