2

尝试在我的 D 驱动器 (D:\TaalTipsDocumenten) 上的文件夹中搜索索引文件时遇到异常 (OleDBException: Not specified Error)。我知道这段代码在过去(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 ErrorCode=-2147467259 HResult=-2147467259 消息=未指定错误 Source=System.Data StackTrace:在 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 映射) 在 System.Data .Common.DataAdapter.FillFromReader(DataSet 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 开始记录,Int32 maxRecords) 在 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 命令,CommandBehavior 行为)在 System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) 在 TaalTips.Controllers.HomeController.Search(String word) 在 D:\Projects\TaalTips\TaalTips \Controllers\HomeController.cs:第 40 行,位于 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase 控制器,Object[] 参数) 的 lambda_method(Closure , ControllerBase , Object[] ) 在 System.Web.Mvc.ReflectedActionDescriptor.Execute( ControllerContext 控制器上下文,IDictionary字典2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 个参数)在 System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult 的 System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult 的 System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) 2.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.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(),但给出相同的错误

有人有什么想法吗?

提前致谢 !

4

1 回答 1

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


                    }

                }
            }
        }
    }
}
于 2017-07-25T12:59:42.697 回答