I'm using the Windows Search API from C# (OleDB access) to retrieve all the index entries on a local machine (Windows 8.1) search index using the following C# code:
string query = @"SELECT System.ItemNameDisplay,SYSTEM.ITEMURL,System.DateModified, System.ItemName, System.Search.AutoSummary,System.Search.GatherTime FROM SystemIndex";
query = query + "WHERE System.Search.GatherTime > '" + LastRunTime.ToString("yyyy-MM-dd h:mm:ss") + "' Order by System.Search.GatherTime Desc";
string connectionString = "Provider=Search.CollatorDSO;ExtendedProperties=\"Application=Windows\"";
OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();
OleDbCommand command;
command = new OleDbCommand(query, connection);
Cursor.Current = Cursors.WaitCursor;
reader = command.ExecuteReader();
int iResults = 0;
int iSummaries = 0;
string sDate = "";
string sText = "";
string sFile = "";
while (reader.Read())
{
try
{
sText = reader.GetValue(4).ToString();
sFile = reader.GetString(1);
sDate = reader.GetDateTime(5).ToString();
Debug.Print(iResults + " " + sFile + " " + sDate);
//if (sText != "") { Debug.Print(sText); iSummaries++; }
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
iResults++;
}
I find that that the code crashes non-reproducibly on the While(Reader.Read())
line with the error IErrorInfo.GetDescription failed with E_FAIL(0x80004005). The loop processes about 55,000 of the 76,080 entries. If I comment out sText = reader.GetValue(4).ToString();
then the loop runs much faster, as the Autosummary field is about 1000 characters and is present for most of the entries. No crash occurs in this case . If I set a breakpoint in the loop and step through one entry at a time, the crash occurs much sooner, making me think that it is a timing problem. Has anyone had similar problems with programmatic access to search indexes and found a workaround?
Set CommandTimeout to 0 after defining the OLEdb command with the query and this seems to have fixed the problem.
User contributions licensed under CC BY-SA 3.0