gpt4 book ai didi

c# - Windows 索引搜索 - OleDbException 未指定错误

转载 作者:太空宇宙 更新时间:2023-11-03 15:02:48 27 4
gpt4 key购买 nike

尝试在我的 D 盘 (D:\TaalTipsDocumenten) 上的文件夹中搜索索引文件时出现异常(OleDBException:未指定错误)。我知道这段代码在过去(2 个月前)有效,但当我试图继续处理该项目时,它似乎不再有效了。

在执行以下代码期间,我在以下行中收到错误:

adapter.Fill(dt);

我可以说数据表 (dt) 已正确填充,但在那一行我仍然遇到错误。此外,当尝试将 OleDbDataReader 与 .Next() 函数一起使用时,它会遍历结果并最终向我抛出错误。

var query11 = @"SELECT  System.DateCreated,
System.ItemName,
System.ItemUrl,
System.Size,
System.Search.HitCount FROM SystemIndex " +
@"WHERE scope ='file:D:/TaalTipsDocumenten' AND CONTAINS('" + word + "') ";

FileOverviewModel returnModel = new FileOverviewModel();
returnModel.Files = new List<FileModel>();
returnModel.Search = word;

DataTable dt = new DataTable();

using (OleDbConnection connection = new OleDbConnection(@"Provider=Search.CollatorDSO;Extended Properties=""Application=Windows"""))
using (OleDbCommand command = new OleDbCommand(query11, connection))
using (OleDbDataAdapter adapter = new OleDbDataAdapter(command))
{
adapter.Fill(dt);
}

错误不多说(未指定):

System.Data.OleDb.OleDbException was unhandled by user code ErrorCode=-2147467259 HResult=-2147467259 Message=Not specified error Source=System.Data StackTrace: at System.Data.OleDb.OleDbDataReader.ProcessResults(OleDbHResult hr) at System.Data.OleDb.OleDbDataReader.GetRowHandles() at System.Data.OleDb.OleDbDataReader.ReadRowset() at System.Data.OleDb.OleDbDataReader.Read() at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping) at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue) at System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) at TaalTips.Controllers.HomeController.Search(String word) in D:\Projects\TaalTips\TaalTips\Controllers\HomeController.cs:line 40 at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2 parameters) at System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase
1.End() at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3d() at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.b__3f() InnerException:

我已经尝试了一些东西:

  • 重新启动 Windows 搜索服务
  • 从文件夹中删除索引并重新添加
  • 重启电脑
  • 确保所有连接都已关闭
  • 创建一个不同的文件夹并在那个文件夹上尝试(同样的错误)
  • 使用 OleDbDataReader 和 reader.Next(),但给出相同的错误

有人知道吗?

提前致谢!

最佳答案

这不是答案,而是建议

我会尝试消除 DataAdapter,看看您是否通过 DataTable.Load 获得与 Test1 相同的异常,或者可能与尝试循环结果的 Test2 一样。

两者都不是解决方案,而是一种查看异常是否可能由读取特定数据(可能来自过多的行等)引起的方法。

请注意,在 Test2 中我做了一个专栏。我会尝试这样做,或者所有列都允许循环运行并查看特定行是否抛出异常,然后从那里查看特定列值是否有问题。

using System;
using System.Data;
using System.Data.OleDb;

namespace Demo
{
class Class1
{
void Test1()
{
var word = "Place a hard code value here";
var query11 = @"SELECT System.DateCreated,
System.ItemName,
System.ItemUrl,
System.Size,
System.Search.HitCount FROM SystemIndex " +
@"WHERE scope ='file:D:/TaalTipsDocumenten' AND CONTAINS('" + word + "') ";


DataTable dt = new DataTable();

using (OleDbConnection connection = new OleDbConnection(@"Provider=Search.CollatorDSO;Extended Properties=""Application=Windows"""))
{
using (OleDbCommand command = new OleDbCommand(query11, connection))
{
connection.Open();
try
{
dt.Load(command.ExecuteReader());
Console.WriteLine(dt.Rows.Count);
}
catch (Exception)
{
// place break-pointhere


}

}
}
}
void Test2()
{
var word = "Place a hard code value here";
var query11 = @"SELECT System.DateCreated,
System.ItemName,
System.ItemUrl,
System.Size,
System.Search.HitCount FROM SystemIndex " +
@"WHERE scope ='file:D:/TaalTipsDocumenten' AND CONTAINS('" + word + "') ";


using (OleDbConnection connection = new OleDbConnection(@"Provider=Search.CollatorDSO;Extended Properties=""Application=Windows"""))
{
using (OleDbCommand command = new OleDbCommand(query11, connection))
{
connection.Open();
try
{
var reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
Console.WriteLine($"Date: {reader.GetDateTime(0)}");
}
}
}
catch (Exception)
{
// place break-pointhere


}

}
}
}
}
}

关于c# - Windows 索引搜索 - OleDbException 未指定错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45299796/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com