View Single Post
  #2 (permalink)  
Old January 25th, 2009, 01:14 AM
Old Pedant Old Pedant is offline
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

I don't have the book so I can't see the code, but this is not really an ASP.NET error.

This is an error coming directly from SQL Server and it's basically complaining about the database schema.

Reading that error:
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 most obviously likely cause is that the record you are currently inserting (I would *guess* you are trying to add a picture to an album at that point) has an Id value that does not match any value of dbo.PhotoAlbum.Id. Example: The PhotoAlbum table has (say) albums with Id = 1 and 2 and 3 and you are trying to add a photo to (say) album 6 (since you said that the URL ended with "?PhotoAlbumId=6"). Note that the field in in the "Picture" table (again, I'm guessing as to the table name, but the name of the contraint "FK_Picture_PhotoAlbum" makes this likely) may *NOT* be named "Id". [In fact, in typical MS naming, it probably won't be...more likely something like "PhotoAlbumId".]

So....

First things first, open up a database browser and look in your PhotoAlbum table. *IS* there a record in that table where the ID values is 6??? [Or whatever the "?PhotoAlbumId=" in the problem URL shows you.] If not, clearly that's the root of the problem.

But now fixing it may be harder.

You will need to figure out *WHY* you are getting an invalid PhotoAlbumId in that URL.

So.... DEBUG time. Have you used the DEBUGGER in Visual Studio yet? If so, now's the time to get started. Try to find where that PhotoAlbumId is being generated. It *SHOULD* be getting it from some query where you specify WHICH album to upload the picture to. (e.g., You say "upload to 'Family' album and then you should have a SQL query that finds out that 'Family' is PhotoAlbumId=6.)

Sorry I can't say more; without the code all this is pretty much just educated guessing.