How to fix the error There is already an open DataReader associated with this Command which must be closed first.



I have now applied this fix on my website sunamo.cz/sunamo.net. I had run into this error before when opening several pages in a row, but I did not know what it meant, since I do not use the SqlDataReader or DataReader class anywhere in the application. Then today I tried to open all 7 of my websites, and for the last two the site reported this error: “There is already an open DataReader associated with this Command which must be closed first.”.

I use a DataReader only once in my application, and there I properly close and dispose of the whole SqlDataReader. The first result on Google offered me this solution: http://stackoverflow.com/questions/3839569/error-there-is-already-an-open-datareader-associated-with-this-command-which-mu . Following the answer with the most upvotes, I added to my ConnectionString the setting MultipleActiveResultSets=True;, which the CS generated in the control panel of ASPOne does not include. But it should work in general, not just with ASPOne. The result? Now, when I open any number of pages, no error occurs at all, whether I am logged in or logged out.

Categories

Leave a Reply