ADO.NET, SQL Server, and FOR XML: what's the best practice?

R

Robert Rossney

I have a pretty large store of SQL Server 2K stored procedures that
accept an XML document as their input parameter and return results using
FOR XML RAW.

What's the best way to create C# code that executes these stored procs
and returns an XmlDocument()?

The basic problem is that SQL Server 2K's XML output produces document
fragments (i.e. collections of elements), not documents. To work around
this, I'm presently using a StringBuilder to create a string containing
an opening tag, appending the OuterXml of each XmlTextReader.Read() to
it, and then, when there's no more data, slapping on the end tag,
producing the string, and passing it to XmlDocument.LoadXml().

I've toyed with deriving a class from XmlTextReader that emits the
closing and ending tags, so that I can pass that object to
XmlDocument.Load(). That seems a little roundabout, but it smells like
it's the right solution -- at least, to this mode of the problem.

I've spent a lot of time Googling for the right answer and haven't found
it. Any help would be appreciated.

Thanks,

Bob Rossney
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top