Friday, 03 September, 2004

Unexplained VersionNotFound Exception with ADO.NET

I've run into a problem that has me pretty confused. I'm getting a VersionNotFoundException when trying to change the RowFilter property of a DataView. This happened in a large system that I'm working on, but I've been able to duplicate the behavior in a relatively small (80 lines) sample program.

I posted a message on Microsoft's forum, but haven't received any helpful responses. Perhaps somebody who reads this can help me out. A Google search revealed a few similar problems (although no exact matches), but I didn't see a small reproducible case or any kind of resolution to the problem.

Short explanation of problem:

I have a DataSet with two tables: Legislators and Authors. The Legislators table contains a list of all Legislators who can potentially be an author or coauthor on a bill. The Authors table contains a record for each Legislator who has signed onto the bill as an author or coauthor (the Authors table will contain information for one bill at a time). The DataSet enforces a relation: the LegislatorCode value in an Authors record must match a LegislatorCode that's in the Legislators table. I use a DataView to maintain a view of the Legislators table showing only those legislators who have not signed onto the bill.

This all works on the initial load, as shown in the program below. However, if I then add an Authors record, the DataView isn't updated to reflect the change. That is, even though there now is an Authors record for a legislator, that legislator still shows up in the DataView. So, figuring I had to trigger a refresh of the DataView, I set RowFilter to string.Empty, and then set it back to what it was. I then get an exception "System.Data.VersionNotFoundException: There is no Original data to access."

Further testing shows that this only happens if I accept changes on the Legislators table (i.e. the parent table in the relation). It appears that the code which processes the relation is looking for the child record to have an Original version if the parent has an Original version. It seems to me that it should be looking for the Current version.

I have two questions:

  1. Why doesn't the DataView update when I enter the new Authors record?
  2. Why do I get this exception?

Any help, especially a workaround or somebody pointing out where I'm doing something wrong, would be appreciated.

The sample program is here.