2017-07-25 48 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