读取大的.accdb文件引发异常“远程主机强制关闭现有连接”

本文关键字:主机 连接 文件 accdb 程主机 异常 读取 | 更新日期: 2023-09-27 18:01:45

我调试一些遗留的ASP。. NET应用程序,试图读取一个巨大的。accdb文件(大约。大约55万行)。代码如下:

OleDbConnection sourceConnection = new OleDbConnection(
            "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + destinationFile);
        OleDbDataAdapter sourceAdapter = new OleDbDataAdapter("select * from [" + tableName + "]", sourceConnection);
        DataSet sourceDataSet = new DataSet();
        try
        {
            sourceConnection.Open();
            sourceAdapter.AcceptChangesDuringFill = false;
            sourceAdapter.Fill(sourceDataSet, tableName);
        }
        catch (Exception ex)
        {
            _trace.TraceEvent(TraceEventType.Error, 0, ex.Message);
        }
        finally
        {
            sourceConnection.Close();
        }

在某个时刻,我得到了例外:

"无法从传输连接读取数据:远程主机已强制关闭现有连接"

Server stack trace: 
at     System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)
at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]: 
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Access2010.IAccessService.LoadFromMDB(String destinationFile, String tableName)
at Access2010.AccessService.LoadFromMDB(String destinationFile, String tableName)

有谁知道它可能是什么以及如何修复它吗?根据我的理解,重写SQL查询以小块检索数据的最佳选择。

读取大的.accdb文件引发异常“远程主机强制关闭现有连接”

我只需使用访问内置的Upsizing向导将其全部放入SQL Express数据库,并更改连接字符串。

旁注,不要这样做:

"select * from [" + tableName + "]"

将其改为参数化查询