title: Trying to store XML content into SQL Server 2005 fails (encoding problem)
body: <p>Folks,</p>
  
  <p>I have a webservice that returns data in ISO-8859-1 encoding - since it's not mine, I can't change that :-(</p>
  
  <p>For auditing purposes, I'd like to store the resulting XML from these calls into a SQL Server 2005 table, in which I have a field of type "XML NULL".</p>
  
  <p>From my C# code, I try to store this XML content into the XML field using a parametrized query, something like</p>
  
  <pre><code>SqlCommand _cmd = new SqlCommand("INSERT INTO dbo.AuditTable(XmlField) VALUES(@XmlContents)", _connection);
  
  _cmd.Parameters.Add("@XmlContents", SqlDbType.Xml);
  _cmd.Parameters["@XmlContents"].Value = (my XML response);
  
  _cmd.ExecuteNonQuery();
  </code></pre>
  
  <p>Trouble is - when I run this code, I get back an error:</p>
  
  <blockquote>
    <p>Msg 9402, Level 16, State 1, Line 1<br>
    XML parsing: line 1, character xy, unable to switch the encoding</p>
  </blockquote>
  
  <p>?? I was trying to figure out where and how I could possibly "switch" the encoding - no luck so far. What does this really mean? I cannot store XML with ISO-8859-1 encoding in SQL Server 2005?? Or is there a trick to a) tell SQL Server 2005 to just accept this encoding, or b) to automagically convert the webservice response to UTF encoding before storing in SQL Server?</p>
  
  <p>Thanks for any hints, pointers, tips! 
  Marc</p>