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