title: ADO cannot access SQL Server XML type column using native client (SQLNCLI)
body: <p>i am using ADO, and one of the <em>"native"</em> drivers (e.g. <code>SQLNCLI</code>, <code>SQLNCLI10</code>, <code>SQLNCLI11</code>) to connect to SQL Server (rather than the legacy <code>SQLOLEDB</code> driver).</p>
  
  <p>ADO does not understand the <code>XML</code> SQL Server data type that the native drivers expose:</p>
  
  <pre><code>field: ADOField;
  
  field := recordset.Fields.Items["SomeXmlColumn"];
  </code></pre>
  
  <p>Attempting to access <code>field.Value</code> throws an <code>EOleException</code>:</p>
  
  <ul>
  <li><strong>Source:</strong> Microsoft Cursor Engine</li>
  <li><strong>ErrorCode:</strong> 0x80040E21 (E_ITF_0E21)</li>
  <li><strong>Message:</strong> Multiple-step operation generated errors. Check each status value</li>
  </ul>
  
  <p>The <em>native</em> client drivers (e.g. <code>SQLNCLI</code>, <code>SQLNCLI10</code>, <code>SQLNCLI11</code>) present an <code>Xml</code> data type to ADO as </p>
  
  <pre><code>field.Type_ = 141 //???
  </code></pre>
  
  <p>while the legacy <code>SQLOLEDB</code> driver presents an <code>Xml</code> data type to ADO as <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms675318.aspx" rel="nofollow noreferrer">adLongVarWChar</a>, a unicode string:</p>
  
  <pre><code>field.Type_ = 203 //adLongVarWChar
  </code></pre>
  
  <p>And the <code>VARIANT</code> contained in <code>field.Value</code> is a <a href="http://msdn.microsoft.com/en-us/library/cc237865.aspx" rel="nofollow noreferrer"><code>WideString</code> (technically known as a <code>BSTR</code>)</a>:</p>
  
  <pre><code>TVarData(field.Value).vtype = 8 //VT_BSTR
  </code></pre>
  
  <p>Seems to me that this is a bug in ADO (Windows 7 SP1), and not something i can fix. </p>
  
  <p>How can i fix it?</p>
  
  <h1>Bonus Reading</h1>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/9082907/delphi-with-sql-server-oledb-vs-native-client-drivers">Delphi with SQL Server: OLEDB vs. Native Client drivers</a></li>
  </ul>