There is already an open DataReader associated ……

遇到一个问题,这是问题描述,就是一个错误信息

I have a rather large ASP-NET-2.0 project that I've been developing for some time. 

I'm using System.Data.Common classes for all of my data access, and SQL-2005 as my provider. 

Up to and including Beta-2, everything was working just fine and dandy. 

Then, with the release of RC1, I suddenly started to get the following error:: 
There is already an open DataReader associated with this Command which must be closed first. 

This totally threw me, but I dutifuly started to trace all of my connections & readers to make sure I was closing & disposing of them properly, and all appears to be correct. 

After a bunch of tedious and very time-consuming debugging, I've come to the conclusion that from RC1 onwards, the framework is not correctly disposing of commands and/or readers when requested to, and this is resulting in a connection "remembering" a previously used command... and refusing to allow it's re-use, because you are not supposed to use multiple instances of the same command on a connection. 

If I roll the installation back to Beta-2 and use the same source code... everything runs fine again. 

Note: This is an ASP issue, as my SQL-Server is on a separate machine. 

I reported this to MS during RC1, but nothing was done about it before RTM, which either means it was ignored, or it's considered to be "as designed" and I'm just not using it properly. 

This is a HUGE problem for me, as it will force me to re-write the entire app to use multiple connections instead of the original MARS design... not something I'm looking forward too, and a really inefficient use of my server. 

Before I go off and start work on this, can anyone suggest something I may have missed in the change from Beta-2 to RC1/RTM (they both have the same issue) or suggest a reason why this would suddenly start to happen 

以下是某国外论坛的解决方案,回帖都说好
This is due to a change in the default setting for MARs. It used to be on by default and we changed it to off by default post RC1. So just change your connection string to add it back (add MultipleActiveResultSets=True to connection string).

 

以下是CSDN论坛的方案

 我已经解决问了,检查所有关于数据库的操作,确保在一个darareader对象没有close以前,在这个connection对象上不再进行其它数据操作就可以了!   

经检测还是CSDN的方案治本,而开启datareader多线程运行几次还是会出问题.

好,国人很强大,结帖!

fail: 2023/7/14 14:31:33.417 CoreEventId.QueryIterationFailed[10100] (Microsoft.EntityFrameworkCore.Query) An exception occurred while iterating over the results of a query for context type 'iMES.Core.EFDbContext.SysDbContext'. System.InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first. at Microsoft.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command) at Microsoft.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command) at Microsoft.Data.SqlClient.SqlCommand.ValidateCommand(Boolean isAsync, String method) at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method) at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at Microsoft.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) at Microsoft.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject) at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.InitializeReader(Enumerator enumerator) at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.<>c.<MoveNext>b__21_0(DbContext _, Enumerator enumerator) at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded) at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.MoveNext()
07-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值