Typed DataSet ReadXML Error

  • Thread starter Jordan Breckenridge via .NET 247
  • Start date
J

Jordan Breckenridge via .NET 247

I have an application with a typed dataset. The application worksfine if I fill the dataset from a SQL Server connection.However, recently, I've been trying to change the application sothat it reads from an XML file. This was supposed to be easy,but its turning out not to be.

I instantiate my dataset subclass, load the data from thedatabase, and then write the XML using the WriteXML(outfilename, System.Data.XmlWriteMode.WriteSchema) to create anXML file with Schema. My plan is to save this file off and notuse a database for production hosting because my applicationisn't really transactional (trying to save some hosting costs).Creating the file is no sweat.

However, when I try to read file into a DataSet using ReadXML andan explicit System.Data.XmlReadMode.ReadSchema, I get an"Invalid 'key' node inside constraint named: [Constraint Name]"exception. I've scoured the web and the schema to see if I canidentify something wrong, but I haven't found anything of note.

On one post, someone suggested changing the msData:isDataSet flagin the schema from "True" to "False". I'm not sure I understandthe logic, but I tried this. I read the file, but I getdifferent errors (see below for a summary of the scenarios).

On MSDN I saw a note that there is a known bug with row states onXML-based datasets and you should copy the dataset prior tobinding it to work around the problem. This seems to dosomething, but again, I get different errors.

I've tried every scenario I can think of: Reading vs. Ignoringthe Schema, Changing "IsDataSet" between False and True, andcopying vs. not copying prior to binding. Here are my results:

(1) Read Schema; IsDataSet=True -- Results in: Invalid 'key' nodeinside constraint named: [Constraint Name]" exception
(2) Read Schema; IsDataSet=False; Copy Prior to Bind -- Resultsin: The name '[DataSetName]' is invalid. A datatable cannot havethe same name of the dataset.
(3) Read Schema; IsDataSet=False; Don't Copy Prior to Bind --Results in: Application runs, but the result is an emptydatalist.
(4) Ignore Schema; IsDataSet=True; Copy Prior to Bind -- Resultsin: Object reference not set to an Instance of an object when aDataView is bound to the DataList.
(5) Ignore Schema; IsDataSet=True; Don't Copy Prior to Bind --Results in: Application runs, but the result is an emptydatalist.
(6) Ignore Schema; IsDataSet=False; Copy Prior to Bind -- Resultsin: Object reference not set to an Instance of an object when aDataView is bound to the DataList.
(7) Ignore Schema; IsDataSet=False; Don't Copy Prior to Bind --Results in: Application runs, but the result is an emptydatalist.

Again, the application works fine if I load the DataSet from thedatabase. Its just when I use the ReadXML methods that itdoesn't work. Can anyone suggest anything else that I should betrying?

Thanks,
Jordan
 
C

Cor Ligthert

Hi Jordan,

Are you able to open the XML dataset file in the IDE.

That gives you mostly direct the error with the affected line.

(Setting it from XML to datamode)

As you wrote normaly this should be very easy and give no problems.

I hope this helps?

Cor
 
K

kanuk_eh

I just ran into this exact same problem in my data handler..

What I did after reading about others having this problem is to first create a ordinary dataSet..



dataSet = new DataSet(dataSetName);

Then I read the schema and data into the dataset using:

dataSet.ReadXmlSchema(schemaFile);
dataSet.ReadXml( fullFileName,XmlReadMode.IgnoreSchema);

Then I created the strongly Typed Data Object
and merged the data that was just loaded into the the DataSet..

MyTypedData dataObject = new MyTypedData()
((DataSet)dataObject).Merge(dataSet);

Pretty sad that you have to do this but it seems to work.

My data handler reads and writes dozens of dataSets/strongly typed datasets for various applications and only a couple with certain relationships defined create this data error..but fingers crossed..this seems to be working..





**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top