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.
这篇关于“阅读器关闭时调用读取的尝试无效"错误(仅适用于冗长的操作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“阅读器关闭时调用读取的尝试无效"错误(仅适用于冗长的操作)
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- 使用 rss + c# 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01