473,466 Members | 1,503 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Constraint validation errors

Is there a way to see constraint validation errors while loading xml into a
DataSet ? I'm interested in the line number in the xml file which is causing
the error. I've enclosed the relevant stack trace below.

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)

Sudip
Nov 11 '05 #1
2 5157
Sudip Chakraborty wrote:
Is there a way to see constraint validation errors while loading xml into a
DataSet ? I'm interested in the line number in the xml file which is causing
the error. I've enclosed the relevant stack trace below.

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)


Well, if you mean validation against XML Schema, use XmlValidatingReader
set on top of XmlReader. See "Validation of XML with
XmlValidatingReader" [1] for more info.

[1]
http://msdn.microsoft.com/library/de...tingreader.asp
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
Thanks for the response.

I'm already validating against the Schema using XmlValidatingReader but
that only gives the errors related to the presence/absence/ordering of
elements/attributes defined in the schema. I'll explain in the context of
the attached schema (BizScapeDataSet.xsd). The schema pertains to a DataSet
with one table BizScape. The primary key (Id) of this table is
AutoIncremented. I do the following in my code (see Code Block). When the
last line executes -- bizScapeDataSet.ReadXml(userXml) -- if there are two
BizScape elements in the Xml file with the same value for Id, then I get an
exception (Constraint violation).

What I would like to know is - which line in the Xml file is causing this
violation. This would be very useful when the Xml file is large and errors
have crept into it - such as duplicate id's.

Sudip

----------------------------- Code
Block --------------------------------------------------------

BizScapeDataSet bizScapeDataSet = new BizScapeDataSet();

// Read the BizScapeDataSet schema

XmlTextReader dataSetSchema =
SomeUtilityClass.ReadXml("BizScapeDataSet.xsd");

// Read in the Xml user data corresponding to the above schema

XmlTextReader userXml = new XmlTextReader("some user file name");

// Do schema validation

XmlSchemaCollection xmlSchemaCollection = new XmlSchemaCollection();

xmlSchemaCollection.Add(null, dataSetSchema);

XmlValidatingReader xmlValidatingReader = new XmlValidatingReader(userXml);

xmlValidatingReader.Schemas.Add(xmlSchemaCollectio n);

xmlValidatingReader.ValidationEventHandler +=

new ValidationEventHandler(this.OnValidationCallback);

while (xmlValidatingReader.Read()) {

}

// Load the Schema into the data set

bizScapeDataSet.ReadXmlSchema(dataSetSchema);

// Load the user data

bizScapeDataSet.ReadXml(userXml);

------------------------
BizScapeDataSet.xsd ----------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="BizScapeDataSet"
targetNamespace="http://voxvue.com/BizScapeDataSet.xsd"
elementFormDefault="qualified" attributeFormDefault="qualified"
xmlns="http://voxvue.com/BizScapeDataSet.xsd"
xmlns:bzs="http://voxvue.com/BizScapeDataSet.xsd"
xmlns:mstns="http://voxvue.com/BizScapeDataSet.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">

<xs:element name="BizScapeDataSet" msdata:IsDataSet="true">

<xs:complexType>

<xs:choice maxOccurs="unbounded">

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

</xs:choice>

</xs:complexType>

<!-- Primary Keys -->

<xs:unique name="pk_bizscape_id" msdata:PrimaryKey="true">

<xs:selector xpath=".//BizScape" />

<xs:field xpath="Id" />

</xs:unique>

</xs:element>

<!-- Type Definitions -->

<xs:complexType name="BizScape">

<xs:sequence>

<xs:element name="Id" msdata:AutoIncrement="true" msdata:ReadOnly="true"
msdata:AutoIncrementSeed="1" type="xs:int" />

<xs:element name="Name" type="xs:string" msdata:AllowDBNull="false" />

</xs:sequence>

</xs:complexType>
<!-- Other Types -->

<!-- Relationships -->
</xs:schema>

"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Sudip Chakraborty wrote:
Is there a way to see constraint validation errors while loading xml into a DataSet ? I'm interested in the line number in the xml file which is causing the error. I've enclosed the relevant stack trace below.

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)
Well, if you mean validation against XML Schema, use XmlValidatingReader
set on top of XmlReader. See "Validation of XML with
XmlValidatingReader" [1] for more info.

[1]

http://msdn.microsoft.com/library/de...tingreader.asp --
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel
"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... Sudip Chakraborty wrote:
Is there a way to see constraint validation errors while loading xml into a DataSet ? I'm interested in the line number in the xml file which is causing the error. I've enclosed the relevant stack trace below.

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)
Well, if you mean validation against XML Schema, use XmlValidatingReader
set on top of XmlReader. See "Validation of XML with
XmlValidatingReader" [1] for more info.

[1]

http://msdn.microsoft.com/library/de...tingreader.asp --
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Kamil | last post by:
Hello What should I use for better perfomance since unique constraint always use index ? Thanks Kamil
12
by: Nalaka | last post by:
Hi, I suddenly started getting a lot of errors from html validation (some CSS) so I followed the following instructions to disable it. If you'd rather not have these types of HTML validation...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
3
by: ferg | last post by:
I have a Customer table. The table has two different CHECK constraints. Then there is the Customer details dialog, which provides the user with an UI for changing users. I have some UPDATE sql,...
3
by: Jeff Kish | last post by:
Hi. I'm getting errors like this when I try to run an upgrade script I'm trying to write/test: altering labels to length 60 Server: Msg 5074, Level 16, State 4, Line 5 The object...
1
by: Spectre1337 | last post by:
Hello, it seems like the check constraint validation of MS SQL Server Management Studio express is horribly, horribly broken. Either that or I'm using it wrong. I hope it's the latter. I'm...
0
by: WJoe | last post by:
This database (Access 2003, Windows XP) has been operational for 2 months now. We enter data into the database using a form. Recently we have been unable to add new records to the database and get...
1
by: tthunder | last post by:
Hi @all, Please check the following XML file and XML schema definition below first: ------- XML File (full): ------- <?xml version="1.0" encoding="UTF-8"?>
8
by: Bryan | last post by:
I want my business objects to be able to do this: class Person(base): def __init__(self): self.name = None @base.validator def validate_name(self): if not self.name: return
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.