2

我正在使用来自 C#(OleDB 访问)的 Windows Search API 使用以下 C# 代码检索本地计算机(Windows 8.1)搜索索引上的所有索引条目:

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++;
}

我发现代码While(Reader.Read())在错误 IErrorInfo.GetDescription failed with E_FAIL(0x80004005) 的行上不可重现地崩溃。该循环处理 76,080 个条目中的大约 55,000 个。如果我注释掉,sText = reader.GetValue(4).ToString();那么循环运行得更快,因为 Autosummary 字段大约有 1000 个字符,并且存在于大多数条目中。在这种情况下不会发生崩溃。如果我在循环中设置一个断点并一次通过一个条目,那么崩溃发生得更快,让我认为这是一个时间问题。是否有人在以编程方式访问搜索索引时遇到过类似的问题并找到了解决方法?

4

1 回答 1

0

在使用查询定义 OLEdb 命令后将 CommandTimeout 设置为 0,这似乎解决了问题。

于 2014-09-10T13:28:26.810 回答