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
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