2017-07-25 46 views
2

尝试在我的D驱动器(D:\ TaalTipsDocumenten)文件夹中的索引文件中搜索时,出现异常(OleDBException:未指定错误)。我知道这段代码在过去(2个月前)工作过,但是当试图继续在该项目上工作时,它似乎不再工作。Windows索引搜索 - OleDbException未指定错误

在下面的代码的执行,我得到以下行错误:

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是由用户代码 错误码= -2147467259 的HResult = -2147467259 消息未处理=未指定的错误 源= System.Data 堆栈跟踪: 在System.Data.OleDb.OleDbDataReader.ProcessResults(OleDbHResult小时) 在System.Data.OleDb.OleDbDataReader.GetRowHandles() 在System.Data.OleD System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping映射) System.Data.Common.DataAdapter.FillFromReader(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数据集,DataTable []数据表,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand命令,CommandBehavior行为) at System.Data.Common.DbDataAdapter.Fill(DataTable [] dataTables,Int32 startRecord,Int32 maxRecords, IDbCommand命令,CommandBehavior行为)在D:\ Projects \ TaalTips \ TaalTips \ Controllers \ HomeController.cs中的TaalTips.Controllers.HomeController.Search(String word)System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) :在lambda_method线40 在System.Web.Mvc.ActionMethodDispatcher.Execute(封闭,ControllerBase,对象[]) (ControllerBase控制器,对象[]参数)在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.WrappedAsyncResult 2.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。 <> c__DisplayClass46。b__3f() 的InnerException:

我尝试了一些事情已经:

  • 重新启动Windows搜索服务从文件夹
  • 删除索引,然后重新添加
  • 重新启动计算机
  • 确保所有连接都关闭
  • 创建一个不同的文件夹并尝试该文件夹(同样的错误)
  • 使用OleDbDataReader和reader.Next(),但给了同样的错误

有人有任何想法?

在此先感谢!

回答

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 


        } 

       } 
      } 
     } 
    } 
} 
+0

感谢您的建议。 我已经尝试了使用读取器进行测试2,并且在reader reader.Read()中得到了同样的错误。我在我的帖子中说这是我尝试的最后一点: - 使用OleDbDataReader和reader.Next(),但给出相同的错误 现在就去尝试第一次测试吧! – Dennis

+0

思考Test2,你知道在reader.Next()抛出错误之前执行了多少次读取。您是否尝试删除WHERE子句的包含部分?您是否尝试删除SELECT中的某些字段我可能会先删除ItemUrl,然后重试。 –

+0

我也试过你的Test1选项,但仍然遇到同样的问题。 我也尝试删除所有内容,并从SystemIndex(即使没有WHERE子句)只选择1字段,但我一直得到相同的错误... 需要找到的所有需要​​的记录实际上存储在数据表中在我的测试案例中只有6),但最终他可能会抛出这个错误?不知道为什么。所以它看起来没有什么问题。 – Dennis