我调试了一些遗留的ASP.NET应用程序,它试图读取一个巨大的.accdb文件(aprox。大约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查询以通过小块检索数据的最佳选择。
答案 0 :(得分:0)
我只是使用内置访问的升迁向导将其全部放入SQL Express数据库,并更改连接字符串。
旁注,不要这样做:
"select * from [" + tableName + "]"
改为使其成为参数化查询。