View Single Post
  #1 (permalink)  
Old January 24th, 2009, 10:25 PM
Psyclist Psyclist is offline
Authorized User
Points: 129, Level: 2
Points: 129, Level: 2 Points: 129, Level: 2 Points: 129, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 32
Thanks: 4
Thanked 0 Times in 0 Posts
Default Chapter 13 Error

I've enjoyed the book and have had little difficulty getting through the "Try It Out" exercises until now in Chapter 13. I've been experiencing an error on the 4th "Try It Out" exercise and I'm not sure why.

I went through the exercise twice to see if I made any errors, but didn't detect any. What's weird is that it initially worked just fine, but then errors began to occur.

At the end of the exercise, you're asked to open NewPhotoAlbum.aspx in your browser which is no problem. I enter a new album name, click the "Insert" link and I'm taken to the "ManagePhotoAlbum.aspx" page without problem.

The first time I did this, I was able to enter two "photographs" without problem. On the third, I got an exception error. Each subsequent time I've tried to create a new album, I can't enter any pictures without getting the exception error. I enter the info in the three text boxes and click on the Insert Button and I get the error.

When the error appears the tab on the browser says this:

"The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Picture_PhotoAlbum". The conflict occurred in the database "C:\http://localhost: 1497/ManagePhotoAlbum.aspx?PhotoAlbumId=6"

I know I can simply copy the downloaded form in, but I'd like to understand what is going on if at all possible. Thanks for any help.

The rest of the browser page error information is as follows:


Server Error in '/' Application.

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Picture_PhotoAlbum". The conflict occurred in database "C:\BEGASPNET\SITE\PLANET WROX\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\PLANET WROX\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:

[SqlException (0x80131904): The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Picture_PhotoAlbum". The conflict occurred in database "C:\BEGASPNET\SITE\PLANET WROX\APP_DATA\PLANETWROX.MDF", table "dbo.PhotoAlbum", column 'Id'.The statement has been terminated.] System.Data.SqlClient.SqlConnection.OnError(SqlExc eption exception, Boolean breakConnection) +1948826 System.Data.SqlClient.SqlInternalConnection.OnErro r(SqlException exception, Boolean breakConnection) +4844747 System.Data.SqlClient.TdsParser.ThrowExceptionAndW arning(TdsParserStateObject stateObj) +194 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392 System.Data.SqlClient.SqlDataReader.ConsumeMetaDat a() +33 System.Data.SqlClient.SqlDataReader.get_MetaData() +83 System.Data.SqlClient.SqlCommand.FinishExecuteRead er(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297 System.Data.SqlClient.SqlCommand.RunExecuteReaderT ds(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(Com mandBehavior behavior, String method) +141 System.Data.SqlClient.SqlCommand.ExecuteDbDataRead er(CommandBehavior behavior) +12 System.Data.Common.DbCommand.ExecuteReader() +12 System.Data.Linq.SqlClient.SqlProvider.Execute(Exp ression 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.DynamicIns ert(TrackedObject item) +136 System.Data.Linq.StandardChangeDirector.Insert(Tra ckedObject item) +202 System.Data.Linq.ChangeProcessor.SubmitChanges(Con flictMode failureMode) +236 System.Data.Linq.DataContext.SubmitChanges(Conflic tMode failureMode) +331 System.Data.Linq.DataContext.SubmitChanges() +19 System.Web.UI.WebControls.LinqToSqlWrapper.SubmitC hanges(DataContext dataContext) +9 System.Web.UI.WebControls.LinqDataSourceView.Inser tDataObject(Object dataContext, Object table, Object newDataObject) +83 System.Web.UI.WebControls.LinqDataSourceView.Execu teInsert(IDictionary values) +448 System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +86 System.Web.UI.WebControls.ListView.HandleInsert(Li stViewItem item, Boolean causesValidation) +277 System.Web.UI.WebControls.ListView.HandleEvent(Eve ntArgs e, Boolean causesValidation, String validationGroup) +652 System.Web.UI.WebControls.ListView.OnBubbleEvent(O bject source, EventArgs e) +233 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.ListViewItem.OnBubbleEve nt(Object source, EventArgs e) +112 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.Button.OnCommand(Command EventArgs e) +118 System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +166 System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection 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.3053