Already Open DataReader

Today I was getting following error when running one of our applications:

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

This happens when you have multiple DataReaders open on the same connection. Note that this can also be because you’re iterating through LINQ query results, which internally also use DataReaders.

To solve this (on SQL Server 2005 + .NET 2.0 or later) add MultipleActiveResults=True to your connection string.

Licensed under CC BY-NC-SA 4.0; code samples licensed under MIT.
comments powered by Disqus
Built with Hugo - Based on Theme Stack designed by Jimmy