IErrorInfo.GetDescription通过OleDB使用Windows Search API失败,返回E_F

本文关键字:失败 返回 API Search 通过 GetDescription OleDB 使用 Windows IErrorInfo | 更新日期: 2023-09-27 18:21:23

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

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)。该循环处理76080个条目中的大约55000个条目。如果我注释掉sText = reader.GetValue(4).ToString();,那么循环运行得更快,因为Autosummary字段大约有1000个字符,并且存在于大多数条目中。在这种情况下不会发生崩溃。如果我在循环中设置了一个断点,并一次遍历一个条目,那么崩溃会发生得更快,这让我认为这是一个时间问题。是否有人在搜索索引的编程访问方面遇到过类似的问题,并找到了解决方法?

IErrorInfo.GetDescription通过OleDB使用Windows Search API失败,返回E_F

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