By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,016 Members | 1,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,016 IT Pros & Developers. It's quick & easy.

One or more rows contain values violating non-null, unique, or foreign-key constraints

P: n/a
Populating a typed dataset from xml document:

I created an xml schema (attached below), generated a typed dataset from it,
and then programatically I tried to populate the typed dataset by calling
its ReadXml method. I keep getting a constraint exception. I have
validated that my xml matches the schema using xmlspy.

I've included the schema, xml, code and exception information below. I
can't figure out why I would get the exception if my xml validates against
the schema, and the dataset was generated from the same schema.

Exception------------------------------------------------------------------------------:
System.Data.ConstraintException: Failed to enable constraints. One or more
rows contain values violating non-null, unique, or foreign-key constraints.
at System.Data.DataSet.FailedEnableConstraints() at
System.Data.DataSet.EnableConstraints() at
System.Data.DataSet.set_EnforceConstraints(Boolean value) at
System.Data.XmlDataLoader.LoadData(XmlReader reader) at
System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving) at
System.Data.DataSet.ReadXml(XmlReader reader)

Schema--------------------------------------------------------------------------------:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified"
id="UploadParameters">
<xs:complexType name="PHNorMRN">
<xs:choice>
<xs:element name="PHN" type="xs:string" maxOccurs="1" minOccurs="1" />
<xs:element name="MRN" type="xs:string" maxOccurs="1" minOccurs="1" />
</xs:choice>
</xs:complexType>
<xs:element name="Upload">
<xs:complexType>
<xs:sequence>
<xs:element name="MRNorPHN" type="PHNorMRN" maxOccurs="1" minOccurs="1"
/>
<xs:element name="From" type="xs:string" maxOccurs="1" minOccurs="1" />
<xs:element name="SourceName" type="xs:string" maxOccurs="1"
minOccurs="1" />
<xs:element name="File" type="File" maxOccurs="unbounded" minOccurs="1"
/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="File">
<xs:sequence>
<xs:element name="FileName" type="xs:string" maxOccurs="1" minOccurs="1"
/>
<xs:element name="Data" type="xs:base64Binary" maxOccurs="1"
minOccurs="1" />
<xs:element name="CreateDateTime" type="xs:dateTime" maxOccurs="1"
minOccurs="1" />
<xs:element name="Description" type="xs:string" maxOccurs="1"
minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:schema>

Xml-----------------------------------------------------------------------------------:
<Upload>
<MRNorPHN>
<MRN>mrn</MRN>
</MRNorPHN>
<From>from</From>
<SourceName>source</SourceName>
<File>
<FileName>C:\\Documents and Settings\\chaj17\\Desktop\\test.txt</FileName>
<Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 1/3</Description>
</File>
<File>
<FileName>C:\\Documents and Settings\\chaj17\\Desktop\\test.txt</FileName>
<Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 2/3</Description>
</File>
<File>
<FileName>C:\\Documents and Settings\\chaj17\\Desktop\\test.txt</FileName>
<Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 3/3</Description>
</File>
</Upload>

Code-----------------------------------------------------------------------------------:
public string UploadDocuments(string strXml)
{
System.Xml.XmlTextReader pXmlReader = new XmlTextReader(new
System.IO.StringReader(strXml));
dsUploadParameters.ReadXml(pXmlReader); //<<--Exception generated here.
...
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
What version of the .NET framework are you using?

"Jeremy Chapman" <me@here.com> wrote in message
news:O9**************@TK2MSFTNGP10.phx.gbl...
Populating a typed dataset from xml document:

I created an xml schema (attached below), generated a typed dataset from it, and then programatically I tried to populate the typed dataset by calling
its ReadXml method. I keep getting a constraint exception. I have
validated that my xml matches the schema using xmlspy.

I've included the schema, xml, code and exception information below. I
can't figure out why I would get the exception if my xml validates against
the schema, and the dataset was generated from the same schema.

Exception-------------------------------------------------------------------
-----------: System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints. at System.Data.DataSet.FailedEnableConstraints() at
System.Data.DataSet.EnableConstraints() at
System.Data.DataSet.set_EnforceConstraints(Boolean value) at
System.Data.XmlDataLoader.LoadData(XmlReader reader) at
System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving) at
System.Data.DataSet.ReadXml(XmlReader reader)

Schema----------------------------------------------------------------------
----------: <?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified"
id="UploadParameters">
<xs:complexType name="PHNorMRN">
<xs:choice>
<xs:element name="PHN" type="xs:string" maxOccurs="1" minOccurs="1" />
<xs:element name="MRN" type="xs:string" maxOccurs="1" minOccurs="1" />
</xs:choice>
</xs:complexType>
<xs:element name="Upload">
<xs:complexType>
<xs:sequence>
<xs:element name="MRNorPHN" type="PHNorMRN" maxOccurs="1" minOccurs="1" />
<xs:element name="From" type="xs:string" maxOccurs="1" minOccurs="1" /> <xs:element name="SourceName" type="xs:string" maxOccurs="1"
minOccurs="1" />
<xs:element name="File" type="File" maxOccurs="unbounded" minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="File">
<xs:sequence>
<xs:element name="FileName" type="xs:string" maxOccurs="1" minOccurs="1" />
<xs:element name="Data" type="xs:base64Binary" maxOccurs="1"
minOccurs="1" />
<xs:element name="CreateDateTime" type="xs:dateTime" maxOccurs="1"
minOccurs="1" />
<xs:element name="Description" type="xs:string" maxOccurs="1"
minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:schema>

Xml-------------------------------------------------------------------------
----------: <Upload>
<MRNorPHN>
<MRN>mrn</MRN>
</MRNorPHN>
<From>from</From>
<SourceName>source</SourceName>
<File>
<FileName>C:\\Documents and Settings\\chaj17\\Desktop\\test.txt</FileName> <Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 1/3</Description>
</File>
<File>
<FileName>C:\\Documents and Settings\\chaj17\\Desktop\\test.txt</FileName> <Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 2/3</Description>
</File>
<File>
<FileName>C:\\Documents and Settings\\chaj17\\Desktop\\test.txt</FileName> <Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 3/3</Description>
</File>
</Upload>

Code------------------------------------------------------------------------
-----------: public string UploadDocuments(string strXml)
{
System.Xml.XmlTextReader pXmlReader = new XmlTextReader(new
System.IO.StringReader(strXml));
dsUploadParameters.ReadXml(pXmlReader); //<<--Exception generated here.
...

Nov 12 '05 #2

P: n/a
1.1 service pack 1
"Zafar Abbas" <so*****@somewhere.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
What version of the .NET framework are you using?

"Jeremy Chapman" <me@here.com> wrote in message
news:O9**************@TK2MSFTNGP10.phx.gbl...
Populating a typed dataset from xml document:

I created an xml schema (attached below), generated a typed dataset from

it,
and then programatically I tried to populate the typed dataset by calling
its ReadXml method. I keep getting a constraint exception. I have
validated that my xml matches the schema using xmlspy.

I've included the schema, xml, code and exception information below. I
can't figure out why I would get the exception if my xml validates
against
the schema, and the dataset was generated from the same schema.

Exception-------------------------------------------------------------------
-----------:
System.Data.ConstraintException: Failed to enable constraints. One or

more
rows contain values violating non-null, unique, or foreign-key

constraints.
at System.Data.DataSet.FailedEnableConstraints() at
System.Data.DataSet.EnableConstraints() at
System.Data.DataSet.set_EnforceConstraints(Boolean value) at
System.Data.XmlDataLoader.LoadData(XmlReader reader) at
System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving) at
System.Data.DataSet.ReadXml(XmlReader reader)

Schema----------------------------------------------------------------------
----------:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified"
id="UploadParameters">
<xs:complexType name="PHNorMRN">
<xs:choice>
<xs:element name="PHN" type="xs:string" maxOccurs="1" minOccurs="1" />
<xs:element name="MRN" type="xs:string" maxOccurs="1" minOccurs="1" />
</xs:choice>
</xs:complexType>
<xs:element name="Upload">
<xs:complexType>
<xs:sequence>
<xs:element name="MRNorPHN" type="PHNorMRN" maxOccurs="1"

minOccurs="1"
/>
<xs:element name="From" type="xs:string" maxOccurs="1" minOccurs="1"

/>
<xs:element name="SourceName" type="xs:string" maxOccurs="1"
minOccurs="1" />
<xs:element name="File" type="File" maxOccurs="unbounded"

minOccurs="1"
/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="File">
<xs:sequence>
<xs:element name="FileName" type="xs:string" maxOccurs="1"

minOccurs="1"
/>
<xs:element name="Data" type="xs:base64Binary" maxOccurs="1"
minOccurs="1" />
<xs:element name="CreateDateTime" type="xs:dateTime" maxOccurs="1"
minOccurs="1" />
<xs:element name="Description" type="xs:string" maxOccurs="1"
minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:schema>

Xml-------------------------------------------------------------------------
----------:
<Upload>
<MRNorPHN>
<MRN>mrn</MRN>
</MRNorPHN>
<From>from</From>
<SourceName>source</SourceName>
<File>
<FileName>C:\\Documents and

Settings\\chaj17\\Desktop\\test.txt</FileName>
<Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 1/3</Description>
</File>
<File>
<FileName>C:\\Documents and

Settings\\chaj17\\Desktop\\test.txt</FileName>
<Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 2/3</Description>
</File>
<File>
<FileName>C:\\Documents and

Settings\\chaj17\\Desktop\\test.txt</FileName>
<Data>MQ==</Data>
<CreateDateTime>2005-10-14T13:41:43</CreateDateTime>
<Description>File 3/3</Description>
</File>
</Upload>

Code------------------------------------------------------------------------
-----------:
public string UploadDocuments(string strXml)
{
System.Xml.XmlTextReader pXmlReader = new XmlTextReader(new
System.IO.StringReader(strXml));
dsUploadParameters.ReadXml(pXmlReader); //<<--Exception generated
here.
...


Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.