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多线程运行几次还是会出问题.

好,国人很强大,结帖!

你可能感兴趣的:(There is already an open DataReader associated ……)