Drawing Blanks

Premature Optimization is a Prerequisite for Success

Does System.Data.SqlTypes.SqlXml suck?

leave a comment »

I think System.Data.SqlTypes.SqlXml sucks because:
1. It has nothing to do with Sql Xml. It is simply a factory for creating XmlReaders over streams.
2. Actually, 1 is wrong. If you call the SqlXml(XmlReader) constructor, the SqlXml will copy the contents of the reader into an internal memory stream. So it’s not just a reader interface, it’s a storage implementation.
3. So it mixes two different responsibilities depending on which constructor you call.
4. Who is responsible for disposing the stream that’s being passed to (or created by) the SqlXml?
5. 2, 3 and 4 are not documented.
6. In the current implementation of ADO.Net this class is redundant because fields of the type SqlDbType.Xml contain values of the type String.
7. MSDN misleadingly states “Obtain the XML […] as an XmlReader by calling the CreateReader method”. ( http://msdn.microsoft.com/en-us/library/system.data.sqldbtype.aspx ). But CreateReader is a method of SqlXml. And fields of the type SqlDbType.Xml contain strings, and not SqlXml. In fact, to obtain an XmlReader from a SqlDataReader r you need to r.GetSqlXml(r.GetOrdinal(“field”)).CreateReader();
8. The implemetation of SqlDataReader.GetSqlXml (given by Reflector) is a real mistery:
public virtual SqlXml GetSqlXml(int i)
    SqlXml xml = null;
    if (this._typeSystem != SqlConnectionString.TypeSystem.SQLServer2000)
        return (this._data[i].IsNull ? SqlXml.Null : this._data[i].SqlCachedBuffer.ToSqlXml());
    xml = this._data[i].IsNull ? SqlXml.Null : this._data[i].SqlCachedBuffer.ToSqlXml();
    return (SqlXml) this._data[i].String;
What the heck are the two last lines supposed to mean? The last statement won’t even compile!
9. The best explanation of SqlXml that I’ve found so far is this: http://msdn.microsoft.com/en-us/library/ms971534.aspx 
The article was written in 2004 and it looks like nothing has changed since then.

Written by bbzippo

11/11/2009 at 5:35 am

Posted in programming

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: