SQL 2005 and XML Data Type

by alocurto Email

I was just working with the new XML datatype for SQL 2005 and started getting this error when inserting the value:

XML parsing: line 1, character 45, unable to switch the encoding

I was simply sending a string to a stored proc thinking that would work (it was a string of valid XML)... I was wrong. I did some research and solved the problem by wrapping up the XML String into a SQL XML datatype.

System.Data.SqlTypes.SqlXml xmlSafe = new System.Data.SqlTypes.SqlXml(new System.Xml.XmlTextReader(xmlAsString, System.Xml.XmlNodeType.Document, null));

Sure, it's simple enough but I haven't used the XML type before.

Feedback awaiting moderation

This post has 1 feedback awaiting moderation...

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)