quot;Invalid attempt to call Read when reader is closedquot; error (for lengthy operations only)(“阅读器关闭时调用读取的尝试无效错误(仅适用于冗长的操作))
问题描述
我们有一个操作,其中从 csv 文件中读取超过 100.000 条记录并插入到数据库中.当我使用一个有 10 条记录的文件时,操作在不到一分钟的时间内成功完成.
We have a operation in which more than 100.000 records are read from a csv file and inserted in a database. When I am using a file with 10 records, the operation is completed successfully in less than one minute.
当我使用 100.000 条记录时,我收到以下错误读取器关闭时调用读取无效".10分钟后.是否可以配置任何超时来避免此错误?
When I use 100.000 records, I am getting the following error "Invalid attempt to call Read when reader is closed." after 10 minutes. Is there any Timeout that I can configure to avoid this error?
注意:CommandTimeout 已经设置为零.
Note: The CommandTimeout is already set as zero.
DbCommand cmd = db.GetStoredProcCommand("aspInsertZipCode");
cmd.CommandTimeout = 0;
dataStringToProcess.Remove(dataStringToProcess.Length - 1, 1);
db.AddInParameter(cmd, "@DataRows", DbType.String, dataStringToProcess.ToString());
db.AddInParameter(cmd, "currDate", DbType.DateTime, DateTime.Now);
db.AddInParameter(cmd, "userID", DbType.Int32, UserID);
db.AddOutParameter(cmd, "CountOfUnchangedZipCode", DbType.String, 1000);
DbDataReader rdr = null;
try
{
rdr = (DbDataReader)db.ExecuteReader(cmd);
if (rdr.Read())
{
if (!String.IsNullOrEmpty(Utility.GetString(rdr, "NewZipCode")))
strNewZipCode = strNewZipCode + "," + Utility.GetString(rdr, "NewZipCode");
}
rdr.NextResult();
if (rdr.Read())
{
strRetiredZipCode = strRetiredZipCode + "," + Utility.GetString(rdr, "RetiredZipCode");
}
int TempUnchageZipCount = Convert.ToInt32(db.GetParameterValue(cmd, "CountOfUnchangedZipCode"));
CountOfUnchangedZipCode = CountOfUnchangedZipCode + TempUnchageZipCount;
dataStringToProcess = new StringBuilder();
cntRec = 0;
}
catch
{
if (rdr != null && (!rdr.IsClosed))
rdr.Close();
throw;
}
finally
{
if (rdr != null && (!rdr.IsClosed))
rdr.Close();
}
cmd.Dispose();
推荐答案
原来是MSDTC &交易问题.我更新了组件服务中的 MSDTC 超时.我还更新了应用程序服务器 machine.config 中 System.Transactions 中的超时值.
It was actually MSDTC & Transaction issue. I updated the MSDTC timeout in Component Services. Also I updated timeout values in System.Transactions in machine.config of the application server.
这篇关于“阅读器关闭时调用读取的尝试无效"错误(仅适用于冗长的操作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“阅读器关闭时调用读取的尝试无效"错误(仅适用于冗长的操作)
基础教程推荐
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01