Monday, February 20, 2012

Multiple "returnid" in SQLXML?

SQL Server 2000 SQLXML 3.0
Using a single updategram, I am adding two rows to a single table.
UpdateGram follows:
<updg:root xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:sync updg:nullvalue="IsNULL">
<updg:before />
<updg:after updg:returnid="SysCKey1">
<Name updg:at-identity="SysCKey1" Last="313" First="131"
FKeyTable="Contact" FKey="264" />
</updg:after>
<updg:before />
<updg:after updg:returnid="SysCKey2">
<Name updg:at-identity="SysCKey2" Last="654" First="654"
FKeyTable="Contact" FKey="264" />
</updg:after>
</updg:sync>
</updg:root>
Because I am doing inserts, I need to have the server side generated keys
returned (as accomplished via the “returnid” and “at-identity” attributes).
The command execution is being handled by a “SqlXmlCommand.ExecuteXmlReader”
(C#) method.
The inserts are taking place as both rows are being inserted into the table.
However, I am only seeing one “returnid” element in my return (C#) XmlReader
object.
Return XML follows:
<returnid><SysCKey1>263</SysCKey1></returnid>
When posting the updategram directly to the database via an HTML POST, the
inserts are also taking place, however I receive the following error message:
Only one top level element is allowed in an XML document. Error processing
resource 'http://test...
<returnid><SysCKey1>265</SysCKey1></returnid>
<returnid><SysCKey2>266</SysCKey2></returnid>
My theory is that since the actual XML being returned does not have a valid
root element (that is there are more than one “returnid” elements) that the
XML document is invalid. This is the reason for the POST error, but is
causing the SqlXmlCommand.ExecuteXmlReader method to see only the first
returnid element and discarding the rest. This is only a theory.
Is there anyway to return multiple returnid elements? Perhaps envelop the
return XML in a valid root element to allow for multiples? How would that be
accomplished?
Please put a ROOT element around updg:root like this:
<ROOT>
<updg:root xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:sync updg:nullvalue="IsNULL">
<updg:before />
<updg:after updg:returnid="SysCKey1">
<Name updg:at-identity="SysCKey1" Last="313" First="131"
FKeyTable="Contact" FKey="264" />
</updg:after>
<updg:before />
<updg:after updg:returnid="SysCKey2">
<Name updg:at-identity="SysCKey2" Last="654" First="654"
FKeyTable="Contact" FKey="264" />
</updg:after>
</updg:sync>
</updg:root>
</ROOT>
That should fix the problem.
"Geoff Ely" <GeoffEly@.discussions.microsoft.com> wrote in message
news:89192677-9772-47CE-B324-5AAC15D20743@.microsoft.com...
> SQL Server 2000 SQLXML 3.0
> Using a single updategram, I am adding two rows to a single table.
> UpdateGram follows:
> <updg:root xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
> <updg:sync updg:nullvalue="IsNULL">
> <updg:before />
> <updg:after updg:returnid="SysCKey1">
> <Name updg:at-identity="SysCKey1" Last="313" First="131"
> FKeyTable="Contact" FKey="264" />
> </updg:after>
> <updg:before />
> <updg:after updg:returnid="SysCKey2">
> <Name updg:at-identity="SysCKey2" Last="654" First="654"
> FKeyTable="Contact" FKey="264" />
> </updg:after>
> </updg:sync>
> </updg:root>
> Because I am doing inserts, I need to have the server side generated keys
> returned (as accomplished via the "returnid" and "at-identity"
> attributes).
> The command execution is being handled by a
> "SqlXmlCommand.ExecuteXmlReader"
> (C#) method.
> The inserts are taking place as both rows are being inserted into the
> table.
> However, I am only seeing one "returnid" element in my return (C#)
> XmlReader
> object.
> Return XML follows:
> <returnid><SysCKey1>263</SysCKey1></returnid>
> When posting the updategram directly to the database via an HTML POST, the
> inserts are also taking place, however I receive the following error
> message:
> Only one top level element is allowed in an XML document. Error processing
> resource 'http://test...
> <returnid><SysCKey1>265</SysCKey1></returnid>
> <returnid><SysCKey2>266</SysCKey2></returnid>
> My theory is that since the actual XML being returned does not have a
> valid
> root element (that is there are more than one "returnid" elements) that
> the
> XML document is invalid. This is the reason for the POST error, but is
> causing the SqlXmlCommand.ExecuteXmlReader method to see only the first
> returnid element and discarding the rest. This is only a theory.
> Is there anyway to return multiple returnid elements? Perhaps envelop the
> return XML in a valid root element to allow for multiples? How would that
> be
> accomplished?
>

No comments:

Post a Comment