我在尝试搜索D-drive(D:\ TaalTipsDocumenten)文件夹中的索引文件时遇到异常(OleDBException:未指定错误)。我知道这段代码在过去(2个月前)有效,但是当我试图继续研究该项目时,它似乎不再起作用了。
在执行以下代码期间,我在以下行中收到错误:
adapter.Fill(dt);
我可以说Datatable(dt)填充正确,但我仍然在该行上出错。此外,当尝试使用带有.Next()函数的OleDbDataReader时,它会运行结果并最终将错误抛给我。
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未被用户代码处理 错误码= -2147467259 的HResult = -2147467259 消息=未指定错误 来源= System.Data 堆栈跟踪: 在System.Data.OleDb.OleDbDataReader.ProcessResults(OleDbHResult hr) 在System.Data.OleDb.OleDbDataReader.GetRowHandles() 在System.Data.OleDb.OleDbDataReader.ReadRowset() 在System.Data.OleDb.OleDbDataReader.Read() 在System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping) 在System.Data.Common.DataAdapter.FillFromReader(DataSet数据集,DataTable datatable,String srcTable,DataReaderContainer dataReader,Int32 startRecord,Int32 maxRecords,DataColumn parentChapterColumn,Object parentChapterValue) 在System.Data.Common.DataAdapter.Fill(DataTable [] dataTables,IDataReader dataReader,Int32 startRecord,Int32 maxRecords) 在System.Data.Common.DbDataAdapter.FillInternal(DataSet数据集,DataTable [] datatables,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand命令,CommandBehavior行为) 在System.Data.Common.DbDataAdapter.Fill(DataTable [] dataTables,Int32 startRecord,Int32 maxRecords,IDbCommand命令,CommandBehavior行为) 在System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) 在D:\ Projects \ TaalTips \ TaalTips \ Controllers \ HomeController.cs中的TaalTips.Controllers.HomeController.Search(String word):第40行 在lambda_method(Closure,ControllerBase,Object []) 在System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase控制器,Object []参数) 在System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary
2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2个参数) 在System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult,ActionInvocation innerInvokeState) 在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase
1.End() 在System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) 在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3d() 在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters。&lt;&gt; c__DisplayClass46.b__3f() InnerException:
我已经尝试了一些东西:
有人有任何想法吗?
提前致谢!
答案 0 :(得分:0)
这不是答案,而是建议。
我会尝试删除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
}
}
}
}
}
}