title: KB4022726 breaks windows search query over OleDb
body: <p>We are using windows search to search for document on a remote share, after applying security update KB4022726 this functionality breaks. </p>
  
  <p>Our implementation is using oledb connector for windows search in C#</p>
  
  <blockquote>
    <p>Are there any workarounds besides uninstalling KB4022726?</p>
  </blockquote>
  
  <p><strong>Update</strong>:
  <a href="https://portal.msrc.microsoft.com/en-US/security-guidance/advisory/CVE-2017-8543" rel="nofollow noreferrer">CVE-2017-8543</a> might be related.</p>
  
  <p><strong>Sample program</strong> - that failes efter install of KB4022726</p>
  
  <pre><code>using System;
  using System.Data.OleDb;
  
  namespace windowssearchtest
  {
    class Program
    {
      static void Main(string[] args)
      {
        var computer = "searchserver";
        var filepath = @"documents";
  
        var query = $@"
  Select System.Itemname
  FROM {computer}.systemindex 
  WHERE SCOPE='file:\\{computer}\{filepath}'";
  
        const string ConnectionString = "Provider=Search.CollatorDSO;Extended Properties=\"Application=Windows\"";
  
        OleDbDataReader myDataReader = null;
        OleDbConnection myOleDbConnection = new OleDbConnection(ConnectionString);
        OleDbCommand myOleDbCommand = new OleDbCommand(query, myOleDbConnection);
        myOleDbCommand.CommandTimeout = 180;
  
        try
        {
          myOleDbConnection.Open();
          myDataReader = myOleDbCommand.ExecuteReader();
          if (myDataReader != null &amp;&amp; myDataReader.HasRows)
          {
            Console.WriteLine($"HasRows: {myDataReader.HasRows}");
            while (myDataReader.Read())
            {
            }
          }
        }
        catch (Exception e)
        {
          Console.WriteLine(e.ToString());
        }
      }
    }
  }
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <blockquote>
    <p>System.Data.OleDb.OleDbException (0x80004005): Uspecificeret fejl<br>
    ved System.Data.OleDb.OleDbDataReader.ProcessResults(OleDbHResult hr) 
    ved System.Data.OleDb.OleDbDataReader.GetRowHandles()    ved
    System.Data.OleDb.OleDbDataReader.ReadRowset()    ved
    System.Data.OleDb.OleDbDataReader.Read()    ved
    windowssearchtest.Program.Main(String[] args) i
    C:\projects_local\windowssearchtest\windowssearchtest\Program.cs:linje
    48</p>
  </blockquote>
  
  <p><strong>Update</strong> 2017-06-26
  I have also reproduced this error on a local machine running win10 - 1703
  Windows search still works, but will throw an error when you reach the end of the resultset, or if empty on .ExecuteReader()</p>
  
  <p>We made a hack to work around this, i will not recommend this:</p>
  
  <pre><code>//pseudo code
  while (Wrap(myDataReader))
  &lt;snip&gt;
  function Wrap(myDataReader)
  {
    try
    {
      return myDataReader.Read();
    }
    catch (ex)
    {
     if(ex.HResult == -2147467259) return false; //0x80004005
     throw;
    }
  }
  </code></pre>