Hi
I get the following error in my Web app
"There is already an open DataReader associated with this Command which must be closed first"
Is this because my DB code doesnt have a close method or a using block?
Thanks
Steven
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
EhteshamPosted May 23, 2012, 8:50 AM
Guest UserPosted May 23, 2012, 8:47 AM
After some investigation it turned out I needed to add the MARS (Multiple Active Result Sets) to the Web.Config and set the value to True.
All works fine!
And NO I dont have a Datareader declared explicity - Im using EF.
EhteshamPosted May 23, 2012, 8:29 AM
Your error message says it
if you have used datareader with a connection and left datareader open and trying to use the same connection you will get that error
Check you code again, their must be a datareader
Guest UserPosted May 23, 2012, 8:25 AM
After reading some forums it is suggested I retrieve all my results\return values first, store in a list\collection and then do something with that list?
Guest UserPosted May 23, 2012, 7:49 AM
Guest UserPosted May 23, 2012, 7:41 AM
List
var orderId = usersShoppingCart.SubmitOrder(User.Identity.Name, out orderDetails);
int totalQuantity = 0;
foreach (OrderDetail od in orderDetails)
{
totalQuantity += od.Quantity;
}
Its as if there needs to be a closing or end after the foreach or even a pause before the next part of the method gets called, which in this case redirects to PayPal.
Thanks
Steven
Guest UserPosted May 23, 2012, 6:57 AM
Each method which accesses the DB has a using block which I thought automatically disposes when finished?
EhteshamPosted May 23, 2012, 6:48 AM
MyDataReaderObject.Close();