Welcome to CrankyGoblin.Com Sign in | Join | Help

Public Class GeoffAppleby

Inherits Microsoft.VisualBasic.MVP : Implements IBrainFart
SQLXML = Disappointed Geoff

The most common way I hit a database from ADO.net is to call a storedprocedure, get back a SQLDataReader, and use that to fill some custom I've written. Sometime after that, it's quite common for this object to get XMLserialized.

What if, I thought to myself, the stored procedure actually returned me a nice set of xml that I can use to deserialize my object, instead of calling methods on the SQLDataReader to set each private member of the class?

It's an interesting idea, filled with lots of issues, performance problems especially. Ignoring all practicalities, I thought I'd have a little play.

The way I see it, there are three main options:

  • Can SQL 2000 return me directly the XML I desire, in the shape that matches the serialized form of my object, and can it be easily done based on an XML schema, rather than hand crafting the shaping of the recordset?
  • Can Yukon do it better?
  • What about converting a recordset clientside?

Well, sadly, I know very little about XML in SQL 2000. I know even less about it in Yukon, except that I know xml support has been greatly improved. So client side is where I decided to look.

The first thing I thought of was the SqlXml library in .net. I've never played with it before, so I had a look.

I'm sad.

Sad and extremely disappointed.

I would have thought that since it's sql server specific, that it would just be a part of the System.Data.SqlClient namespace. Nope.

I would have thought that it would work in much the same way. Nope.

Using the normal SqlClient namespace, I can write code like this:

        Dim oConnection As New SqlConnection(sConnectionString)
        Dim oCommand As SqlCommand = oConnection.CreateCommand
        Dim oReader As SqlDataReader

        oConnection.Open()
        oCommand.CommandText = "prSomeProc"
        oCommand.CommandType = CommandType.StoredProcedure
        oCommand.Parameters.Add("@SomeParam", SqlDbType.NVarChar, 50).Value = sSomeValue

        oReader = oCommand.ExecuteReader(CommandBehavior.CloseConnection)

This is pretty nice. I have a connection, a command object, and some parameters. I tell it that it's running a stored procedure, and all is good.

In SqlXml, it's nowhere near this nice. My first try was like this:

        Dim oCommand As New SqlXmlCommand(sConnectionString)
        Dim oParam As SqlXmlParameter
        Dim oReader As System.Xml.XmlReader

        oCommand.CommandText = "prSomeProc"
        oCommand.CommandType = SqlXmlCommandType.Sql
        oCommand.ClientSideXml = True
        oParam = oCommand.CreateParameter
        oParam.Name = "@SomeParam"
        oParam.Value = sSomeValue
        oReader = oCommand.ExecuteXmlReader

This looks fairly similar to my earlier example, but it has some differences. There's no way of specifying that it's a stored procedure being called. There's no parameters collection - you can only ask it for a new one. You can't specify the data type of the parameter.

And does it work? Nope.

When I ran it it complained that the stored procedure required a parameter '@SomeParam'. Umm, excuse me? I supplied it, thankyou very much.

It ends up that even though I've added the parameter, it's not applied because the SqlXml engine is too dumb to realise that they're needed. I had to modify it to this:

        Dim oCommand As New SqlXmlCommand(sConnectionString)
        Dim oParam As SqlXmlParameter
        Dim oReader As System.Xml.XmlReader

        oCommand.CommandText = "exec prSomeProc @SomeParam=?"
        oCommand.CommandType = SqlXmlCommandType.Sql
        oCommand.ClientSideXml = True
        oParam = oCommand.CreateParameter
        oParam.Name = "@SomeParam"
        oParam.Value = sSomeValue
        oReader = oCommand.ExecuteXmlReader

I actually had to specify in the command text that a parameter was part of it.

And so did it now run? Nope. The problem here is that the SqlXml library, who's whole purpose of existence is to manipulate recordsets into XML, didn't want to run because I hadn't told it to actually create some XML.

Here's the final version:

        Dim oCommand As New SqlXmlCommand(sConnectionString)
        Dim oParam As SqlXmlParameter
        Dim oReader As System.Xml.XmlReader

        oCommand.CommandText = "EXEC prSomeProc @SomeParam=? FOR XML RAW"
        oCommand.CommandType = SqlXmlCommandType.Sql
        oCommand.ClientSideXml = True
        oParam = oCommand.CreateParameter
        oParam.Name = "@SomeParam"
        oParam.Value = sSomeValue
        oReader = oCommand.ExecuteXmlReader

So this actually worked. I could use the returned XmlReader and have a look at the XML. The next step was to see if I could get the XML generated to match a specific schema - say, the schema that matches the XML output of the XMLSerializer when I serialize the appropriate custom object involved.

This is where I stopped. You can specify a schema, and even a transform, but only by providing the file location of the .xsd and .xslt files. You can't pass it anything that is currently in memory.

This is utter bullshit. Specifying the commandtext is extremely limited. Parameters are inflexible. Manipulation is limited to the file system.

Go to hell SqlXml, I say, go directly to hell, do not pass go, do not collect $200.

Posted: Saturday, 28 May 2005 10:55 PM by Geoff Appleby
Filed under:

Comments

TomCat said:

-- do not pass go, do not collect $200

LOL.
# May 29, 2005 9:25 AM

jkimble said:

Dunno if this is of interest but check out these DonXML posts (I was humbly involved in the beginnning)... he links to my old post, but since the move from dnj I have no idea where the original post is anymore... I guess if you follow the links you'll eventually get here to CodeBetter...

http://donxml.com/allthingstechie/archive/2004/06/01/762.aspx
http://donxml.com/allthingstechie/archive/2004/06/25/862.aspx

Don had a follow up later on the .Net 2.0 version being closer, but still not as fast as a Dataset...

Jay
# May 29, 2005 11:16 AM

Kevin said:

If you have a simple object that you want to serialize into, then FOR XML AUTO should be an easy option for you. I was thinking of doing something like this on some of my simple entities, but just haven't done it yet but maybe I'll try it this week.

Here is a MSDN link to info about FOR XML AUTO http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsql/ac_openxml_1hd8.asp
# May 31, 2005 7:28 AM

Don Demsak said:

Did you get a chance to check out my code? You don't need to use the SQLXML lib to return XML from a sproc, as long as you use the For Xml clause in the sproc. For XML Auto is kind of sucky, since it treats every join as another hierarchy level (which isn't always the case), but there is always For Xml EXPLICIT, which lets you sort of kind of roll your own XML (thru a nasty hack by embedding the info in the AS clause of the select statement). The sproc FOR XML stuff works the same as the Client side SQLXML stuff, but since the sproc stuff is usually on a beefer machine (and it usually has less info to transfer over the wire), it is faster then the client side stuff. Another turnoff for the SQLXML lib in .Net, it is only a wrapper for the old ADO XML stuff (yes the COM version).

Other gotchas that you probably didn't think of:

The results of a For XML sproc does not have to be a valid XML Doc, since it may not have a root node.
Loading the XML in an XML Document isn't much better then using a DataSet since you have to load the whole thing into memory and then actually do something with it.
Better choice is a XPathDocument (which is optimized for XPath queries).

Contact me if you want some more info.

Don
# June 3, 2005 6:45 PM

Geoff Appleby said:

Hey Don,

Yeah, I had a good read of it all, and I downloaded your sample code where you had a look at the performance of the different ways of getting the data, including serializer and datareader.

Fascinating stuff, no? :)

I've pretty much decided to leave it alone for now, since I was only playing around to begin with. The thing that really disapoints me most is that the hype around Yukon and expected behaviours (based on talks at teched and things) don't match the reality.

Currently when calling procs we generally create a command object, map the parameters in from wherever we need to source it (9 times out of ten, all from the same instance of some custom object), and run the command. What I was hoping for with yukon and embedded CLR is that I could write a .net proc which takes my custom object as the single param, and in _that_ proc map the properties of the object to the params of the real TSQL version of the proc. Returning the reslutset could also have the .net proc map the databack into custom classes that are then returned as a single object (or collection of objects).

While not always the best way to do for performance reasons, doesn't this sound dreamy?

But no, it's not how it works. while we have the clr, we can't pass in and around any damn object we like, only UDTs, which are structs, not classes, and much more constrained in what they can do. Disappointing.

My next thought was to xmlserialize an object in as the only param to the proc, and then parse the xml to find the 'real' params needed. but even in yukon, sp_xml_preparedocument() is stated to reserve an 8th of the available sql server ram, and that's pretty yucky.

So getting the resultset then munged back into xml that could potentially be used directly by the xmlserializer to simply deserialize with seems almost a waste of time, given that i can really only get xml output, not input (not nicely anyway)...and as you say, creating the exact xml you want using for xml explicit is still pretty hacky (and from what i've read, uber complex) anyway.

The main reason for my post in the first place wasn't so much trying to find some interesting solutions to an interesting idea, but that in playing around with soem ideas, SQLXML was pretty damn poor.

But thanks for your comments indeed! I figure in a few months time I might be ready to seriously look again, once I've had a chance to really play with both yukon and whidbey, andhad a chance to find out what new techniques we might better be able to exploit :)
# June 3, 2005 9:56 PM

LeVaN said:

http://www.antique-persian-rugs.seksi-***.com ^^^ http://www.antivirus-gratis.seksi-***.com ^^^ http://www.derisive-agente-di-polizia-masturbate.str0nz0.com ^^^ http://www.bionde-gruppo-sul-partito.str0nz0.com ^^^ http://www.petardas-2-download.100milfotos.com ^^^ http://www.galeria-sex-transex.100milfotos.com ^^^ http://www.sesso-travestis-que-nois.allievo69.com ^^^ http://www.teen-succhi-in-villaggio.allievo69.com ^^^ http://www.mieleinen-tytsyt-***.huor4.com ^^^ http://www.bbw-anime.huor4.com ^^^ http://www.omalaatuinen-***-tupla-kissimirri-naida.hu0ra.com ^^^ http://www.tarjoilijatar-***.hu0ra.com ^^^ http://www.bramare-cameriera-sex.fott1.com ^^^ http://www.jr.fott1.com ^^^ http://www.comfortable-giovane-amore.f0tti.com ^^^ http://www.gradito-idraulico-inculate.f0tti.com ^^^ http://www.maksuton-big-***.s3ksi.com ^^^ http://www.porno-british-bukkake.s3ksi.com ^^^ http://www.fighe-focose-pompini.ragazza69.com ^^^ http://www.adeguato-lesbiche-prostituta.ragazza69.com ^^^ http://www.lesbica-acabadas-vajinales.corneo69.com ^^^ http://www.bukkake-fighette.corneo69.com ^^^ http://www.foto-chulazos.dibujitosporn.com ^^^ http://www.trailer-calatitascom.dibujitosporn.com ^^^ http://www.donne-vecchie-esibizioniste.disponibile69.com ^^^ http://www.password-me-to-podi-eikonidia.disponibile69.com ^^^ http://www.xxx-foto-culturiste.gayfrei.com ^^^ http://www.brigitta-bui-dvd.gayfrei.com ^^^ http://www.hentai-***-pics.petarda2fotos.com ^^^ http://www.videos-maduras-brasileiras.petarda2fotos.com ^^^ http://www.videos-secretarias-violadas.lesbianavideo.com ^^^ http://www.jpg-hombre-sexi.lesbianavideo.com ^^^ http://www.vids-zorras-ardientes.pollonesamateur.com ^^^ http://www.tetas-jovencitas-catalog.pollonesamateur.com ^^^ http://www.chicasreff-mpeg.sexoexnovia.com ^^^ http://www.galerias-porristas-infragantis.sexoexnovia.com ^^^ http://www.chenoa-bikini.latinas-putas.com ^^^ http://www.sexo-chat-gratis.latinas-putas.com ^^^ http://www.amateur-facials-com.putasmorochas.com ^^^ http://www.adolescentes-sexis.putasmorochas.com ^^^

# November 28, 2006 1:31 AM

miki said:

http://collage-turismo.j95c8-r-1.info/ **#**

http://www.jpeq50t4gzp.info/sql-server-microsoft.html **#**

http://otranto-appartamento-vacanza.gzdfwhf.info/ **#**

http://www.jzx87ez9h0.info/accoglienza-roma/ **#**

http://mamme-ciccione-calde.h6yzmdsm.info/ **#**

http://www.ea2gpm6.info/hotel-splendid-napoli.html **#**

http://www.jpeq50t4gzp.info/ludicrous-cameriera-ubriache.html **#**

http://www.hlc4w7c48p.info/voli-economici-partire.html **#**

http://fumetti-bondage.j95c8-r-1.info/ **#**

http://studentessa-prostituta-in-anticamera.j95c8-r-1.info/ **#**

http://www.mdp4vw4oxcdk.info/hp-photosmart-245.html **#**

http://www.dgrgajmcwsu.info/ykygxyi.html **#**

http://vendita-villa-drenchia.jzx87ez9h0.info/ **#**

http://cuttiest-fighette-***.d0tsozq.info/ **#**

http://lust-lesbiche.keuo0.info/ **#**

http://www.bv2x0l2df5r.info/gt5ozovv9k/ **#**

http://piccoli-piesex-gransex-piaceri.gw3x6095.info/ **#**

http://piu-bollente-bionde-masturbate.e71fjt8dy.info/ **#**

http://voli-scontati-venezia.bv2x0l2df5r.info/ **#**

http://www.mdp4vw4oxcdk.info/zoo-york.html **#**

http://www.d0tsozq.info/wepwez9cgq.html **#**

http://parenti-fidanzato.e71fjt8dy.info/ **#**

http://bus-napoli.g4sgtrt7hatu.info/ **#**

http://informatici-sistema.j95c8-r-1.info/ **#**

http://amicizia-relazioni.e71fjt8dy.info/ **#**

http://attractive-cowgirl-figa-fotti.h6yzmdsm.info/ **#**

http://mousy-cameriera-masturbate.mdp4vw4oxcdk.info/ **#**

http://imaggini-porno.e71fjt8dy.info/ **#**

http://grasse-tardone-sex.jpeq50t4gzp.info/ **#**

http://penetrazione-filmato.mdp4vw4oxcdk.info/ **#**

http://www.j95c8-r-1.info/143920404/ **#**

http://www.mdp4vw4oxcdk.info/sorca-di-animali.html **#**

http://www.h6yzmdsm.info/ritirarsi-infermiera-strip/ **#**

http://latex-underwear.bv2x0l2df5r.info/ **#**

http://in-sex-capezzoli.mdp4vw4oxcdk.info/ **#**

http://www.jpeq50t4gzp.info/modelle-milano.html **#**

http://annuncio-free-lazio.i5rio48ku.info/ **#**

http://sardegna-monolocali.mdp4vw4oxcdk.info/ **#**

http://congenial-ragazze-spogliarello.gzdfwhf.info/ **#**

http://lavoro-neolaureati.bv2x0l2df5r.info/ **#**

http://pensioni-isola-d-elba.hlc4w7c48p.info/ **#**

http://www.gzdfwhf.info/video-casalinghe.html **#**

http://bello-asiatiche-fottilo.e71fjt8dy.info/ **#**

http://villaggio-spagna.j95c8-r-1.info/ **#**

http://www.ghkr4icqw.info/ie62h2l.html **#**

http://foto-di-vagine-bagnate.bv2x0l2df5r.info/ **#**

http://www.keuo0.info/sborrate-porno/ **#**

http://sexchevole-fighette-masturbate.gzdfwhf.info/ **#**

# December 29, 2006 11:29 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

To submit your comment, click on these pictures:
  • Angry Geoff
  • Geoff with sunglasses
  • Geoff has an idea
Gaptcha Image - No Peeking! Gaptcha Image - No Peeking! Gaptcha Image - No Peeking!
Gaptcha Image - No Peeking! Gaptcha Image - No Peeking! Gaptcha Image - No Peeking!
Gaptcha Image - No Peeking! Gaptcha Image - No Peeking! Gaptcha Image - No Peeking!
Can't recognise the people in these pictures? Look here for a quick introduction.
There's a time limit for you to get your comment submitted before this set of pictures expires. If you think it's been longer than 10 minutes, get some new pictures first (you won't lose what you've typed so far).
Get some new pictures 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS