0

我调试了一些旧的 ASP.NET 应用程序,它试图读取一个巨大的 .accdb 文件(大约 550 000 行)。代码如下:

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 查询以按小块检索数据的最佳选择。

4

1 回答 1

0

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

旁注,不要这样做:

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

改为参数化查询。

于 2013-03-01T10:46:14.493 回答