我正在构建一个基于 Windows 搜索的搜索模型,特别是 Dsearch 示例,位于 查询文件夹下的以下链接http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=7388中。
问题是,我需要将此搜索方法作为我需要在 asp.net 应用程序中使用的 WCF 服务。正如我发现的那样,问题出在 OleDbConnection 对象中——它通过 Windows 应用程序连接到索引器提供程序——。
它在调用时给出IErrorInfo.GetDescription failed with E_FAIL(0x80004005)异常
OleDbDataReader.read()
我的问题可以将 OleDbConnection 与 WCF 服务一起使用吗?
代码:
// Generate SQL from our parameters, converting the userQuery from AQS->WHERE clause
string sqlQuery = queryHelper.GenerateSQLFromUserQuery(userQuery);
// --- Perform the query ---
// create an OleDbConnection object which connects to the indexer provider with the windows application
System.Data.OleDb.OleDbConnection conn = new OleDbConnection(queryHelper.ConnectionString);
// open it
conn.Open();
// now create an OleDB command object with the query we built above and the connection we just opened.
OleDbCommand command = new OleDbCommand(sqlQuery, conn);
// execute the command, which returns the results as an OleDbDataReader.
OleDbDataReader WDSResults = command.ExecuteReader();
while (WDSResults.Read())
{
nResults++;
// col 0 is always our path in display format
string path = WDSResults.GetString(0);
if (fScope)
{
// if it is relative to the current directory, then just show the relative part of the path
path = path.Substring(Directory.GetCurrentDirectory().Length + 1);
}
if (fDisplayContents)
{
// output the file to our WDSResult file to build the list of files for input to findstr
fileList.Add(path);
}
else
{
List<string> val = new List<string>();
// if they have a custom sort column
if ((fBare == false) && (sortCol != "System.ItemPathDisplay"))
{
// then get it
val[0] = WDSResults.GetValue(1).ToString();
// and output it
return val[0];
}
return val[0] + path;
// output the path
//Console.WriteLine(path);
}
}
WDSResults.Close();
conn.Close();
编辑: 我在控制台应用程序和 WCF 服务中都有完全相同的查询
CommandText = "SELECT \"System.ItemPathDisplay\" FROM \"SystemIndex\" WHERE CONTAINS(*,'\"soa*\"',1033) AND scope='file:D:\\4Project' ORDER BY System.ItemPathDisplay ASC"
CommandText = "SELECT \"System.ItemPathDisplay\" FROM \"SystemIndex\" WHERE CONTAINS(*,'\"soa*\"',1033) AND scope='file:D:\\4Project' ORDER BY System.ItemPathDisplay ASC"