471,084 Members | 962 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,084 software developers and data experts.

SqlXmlException - Schema: relationship expected on <element name>. Help!

Ok, brand new to SQLXML 3.0 and its various issues. Heres what I'm
trying to do:

1. I am trying to load xml data into an empty SQL table from my .NET
console application.
2. This isn't a huge amount of data so I'm not interested in
BulkXMLLoad (or whatever its called).
3. I have the xml and xml schema ready to go, with (I hope) the proper
sql annotations.

Heres my xml schema (built via xsd tool with added sql annotations):

<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-micrsooft-com:mapping-schema">
<xs:element name="Visitors" nillable="true" type="VisitorList"
sql:is-constant="1" />
<xs:complexType name="VisitorList">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Visitor"
type="VisitorInfo" sql:relation="LiveMeetingAttendeesBMO1" />
</xs:sequence>
<xs:attribute name="Count" type="xs:int" use="required"
sql:mapped="false" />
</xs:complexType>
<xs:complexType name="VisitorInfo">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="ID"
type="xs:string" sql:mapped="false" />
<xs:element minOccurs="0" maxOccurs="1" name="userName"
type="xs:string" sql:field="Name" />
<xs:element minOccurs="0" maxOccurs="1" name="Role"
type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="email"
type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="company"
type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="ipAddress"
type="xs:string" sql:field="[IP Address]" />
<xs:element minOccurs="0" maxOccurs="1" name="browser"
type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="meetingName"
type="xs:string" sql:field="[Meeting ID]" />
<xs:element minOccurs="1" maxOccurs="1" name="duration"
type="xs:int" />
<xs:element minOccurs="1" maxOccurs="1" name="meetingTime"
type="xs:dateTime" sql:field="[Activity Day and Time]" />
<xs:element minOccurs="1" maxOccurs="1" name="startTime"
type="xs:dateTime" sql:field="Arrived" />
</xs:sequence>
</xs:complexType>
</xs:schema>

As you can see, one Visitor record should apply to one record in the
backend SQL table, named LiveMeetingAttendeesBMO1.

Heres my code to post to the database:

public void PostToDatabase(ConferenceType confType, MeetingInfo
Meeting)
{
SqlXmlCommand cmd = new SqlXmlCommand(Configuration.ConnectionString);
cmd.RootTag = "ROOT";
cmd.CommandType = SqlXmlCommandType.XPath;
cmd.CommandText = "LiveMeetingAttendeesBM01";
cmd.SchemaPath = "../../XML/VisitorList_Events.xsd";

DataSet dataset = new DataSet();
SqlXmlAdapter adapter = new SqlXmlAdapter(cmd);
adapter.Fill(dataset); //-- ERROR HITS HERE

//this serializes class into XML according to schema above.
XmlTextReader reader = ConvertToXML();

//now load dataset with new records and update database!
dataset.ReadXml(reader, XmlReadMode.Auto);
adapter.Update(dataset);
}

The "adapter.Fill(dataset)" line causes the error - SqlXmlException:
Schema: relationship expected on 'Visitor'.

I'm not sure why this is appearing... there is no join here, so I don't
need a relationship right? I also map my Visitor elements to records in
the LiveMeetingAttendeesBMO1 table via the "sql:relation" attribute.

Has anyone seen anything like this?

NOTE: The sql:is-constant='1' attribute in the schema - the results are
the same with or without it.

Thanks for the help!! :)

J'son

Nov 12 '05 #1
2 7310
Some clarity after banging my head on my desk:

I think that since my initial table in the SQL database is empty, the
fill code is unnecessary. Also, in reading some more I figured out that
the CommandText refers to the XSD file of the SqlXmlCommand when using
CommandType = XPath (duh!). So here is the updated PostToDatabase()
function:

public void PostToDatabase(ConferenceType confType, MeetingInfo
Meeting)
{
SqlXmlCommand cmd = new
SqlXmlCommand(Configuration.ConnectionString);
cmd.CommandText = "Visitor";
cmd.CommandType = SqlXmlCommandType.XPath;
cmd.SchemaPath = "../../XML/VisitorList_Events.xsd";

DataSet dataset = new DataSet();
SqlXmlAdapter adapter = new SqlXmlAdapter(cmd);

//this serializes class into XML according to schema above.
XmlTextReader reader = ConvertToXML();

dataset.ReadXmlSchema(cmd.SchemaPath);
dataset.ReadXml(reader, XmlReadMode.ReadSchema);
dataset = dataset.GetChanges(DataRowState.Added);

adapter.Update(dataset); //-- ERROR NOW HAPPENS
HERE (SAME ERROR)
}

Same error occurs, just now on the adapter.Update method so its still
an issue with my schema.

Thanx!

Sincerely,

J'son

Nov 12 '05 #2
Figured it out... check out my urn for the xmlns:sql namespace in the
schema - micrsooft! Arrrggh... :P

J'son

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Christopher | last post: by
4 posts views Thread by Don Wash | last post: by
1 post views Thread by mahesh.kanakaraj | last post: by

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.