J.J.Baxter - My place on the web - interests, hobbies, thoughts & ruminations
Home / Blog
Books
Links
Images
Aug Sep-2010 Oct
SMTWTFS
2930311234
567891011
12131415161718
19202122232425
262728293012
3 4 5 6 7 8 9
Reset Calendar
Snorg Girls
Programming Tips
Sherlock Holmes
Mythbusters
Gallipoli
Nova Science Now
Ajax Loading Images
The Girls of Dr. Who
Keratosis Pilaris (KP)
Amazing Water
Buy me a drink? I'll have a Cappuccino, thanks.
Random Images
Random Link
Serenity Browncoats
Random Book
The Bourne Ultimatum
by Robert Ludlum






All Rights Reserved 2008
JJBaxter.com

J.J.Baxters Development Tips & Snippets
backBack
 There is already an open DataReader associated with this Command which must be closed first (ASP.NET : 08-Jul-2009)

There is already an open DataReader associated with this Command which must be closed first

This error poped up when trying to convert a web app that used an OLEDB connection to an SQL server to use a SQL connection.

A brief googling found a page that said you should use fresh connection with each command/request. This seemed stupid considering under OLEDB I could have multiple command/request with just one connection. So I just stayed with OLEDBD.

Then today it happened with a project that required SQL connections only (dont ask). I diferently worked google search led me straight to the reference link below. SQL connections by default only allow one request per connection. Adding MultipleActiveResultSets=True to the connection string solved the problem.

my connection string now looks like this:

Data Source=192.xxx.xxx.x; Initial Catalog=BookingsData; User Id=sqluser; Password=sqlpass; MultipleActiveResultSets=True


Now I will only be using SQL connections.

Update: Sometimes IIS looses the ability to understand the MultipleActiveResultSets=True parameter, usually after a system restore or other interuption. I have fixed this successfully by re-installing Dot.Net 2 as shown below:

1. Open a command prompt
2. Stop IIS: iisreset /stop
3. Change to the .NET Framework 2.0 root directory: C:\winnt\Microsoft.Net\Framework\v2.0.50727\
4. Reinstall ASP.NET 2.0 by using the following command: aspnet_regiis -i
5. Start IIS again: iisreset /start
Ref Link: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/78d3989a-8975-4930-998d-1eb907966f57