Absulute Beginner's Video Series RSS Reader Project - ConstraintException  
Author Message
dLloydm





PostPosted: Visual C# Express Edition, Absulute Beginner's Video Series RSS Reader Project - ConstraintException Top

When I programmed the Rss Reader I get a ConstraintException error for the NewsItemID at the Update() method when running the refreshRssFeed. Only one record is stored and when storing the second it seems that the NewsItemID is not being incremented. If I click the refresh rss again I get the exception on the next consecutive NewsItemID and another record is stored. I can continue storing this way one record at a time. I have put the Update() method in a try/catch block with a message box displaying the exeception.

Further testing reveiled that it only gets the exception when the NewsItems table is initially empty when the program loads. I then used the downloaded code from the author and deleted the records in the NewsItems table and corrected a link in the Channels table that dosn't exist. The author's code also gets the same error when the table is initally empty. The author also has the database property set to copy newer. With that setting the program works the next time it is loaded since a record has been stored.

I also noticed that although the author has code that is supposed to prevent duplicate items in the NewsItem table, it dosn't appear to be working.

Has anyone else tried this

I also created a simple test program using a similar DB structrue and update senerio, less all the XML & internet access, and there was no problem.




Visual Studio Express Editions40  
 
 
dLloydm





PostPosted: Visual C# Express Edition, Absulute Beginner's Video Series RSS Reader Project - ConstraintException Top

I have found a solution to this problem, but I don't know if I can explain completly why.  Based on the number of replies this question received I would guess that the disconnected dataset stuff is not well understood.

What I finally found after several days testing various combinations of things is that the dataset wizard setup different properties for the columns in the dataset.  In the database the Identity properties defaults were used.  Identity Increment = 1, and Identity Seed = 1.  But when the dataset was generated the AutoIncrementSeed was 0 and the AutoInrementStep was 1.

I am not sure of how I genereated the dataset, but during testing I stripped the original program down to nothing but the single table with an ID column for the PK and a text column.  I used a loop to generate values for the text column for 100 rows.  I did delete and regenerate the dataset and database several times to see if I could make the Update work.  I then generated a new application from scratch that was virtually identical and it worked fine.  Then through extensive used of the watch window I compared step by step every value generated and notice that the newrow() method of the original application was creating a dataset row with an ID of 0.  In the immediate window I changed this value to 1, and it worked.  In the scratch version the ID value was generated as 1.  Then I checked the dataset properties for the ID field of the new version in the dataset designer and found the the AutoIncrementSeed was 1, not 0.

I then when to the original applications, including the version downloaded for the video series from microsoft, and changed this property from 0 to 1.  I also reset the database property by setting the Identity property to no and back to yes.  Now they all work.

I also fixed the dupe check.  The author had removed quotes from the title and also took the first 50 character substring for longer titles before storing in the database.  It was these changed titles that were not found in the dupe check.  I modified the dupe check to use the adjusted title in the comparison and no more dupes.

If anyone understands more about the dataset/database Seed thing, I still have questions as to why it didn't work and why my solution worked.  In my initial troubleshooting I created a scratch program that worked and the dataset seed was 0.

Thanks for your time.