views:

39

answers:

0

Using a DbContext (CTP4) I have the following setup. It works great, but if I exit the first context and then make a new one, and try to query anything, I get the exception..

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

I obviously suspect the problem is that the connection is still open, despite being enclosed in the 'using' block (which should have disposed of it at the end, right?)

public class SampleDataContext : DbContext
{
 // ...
}

(most of the code in there is unimportant)

this all works fine. I can make my context just fine.

using(var context = new SampleDataContext(model))
{
 // execute some code. Add records, etc.
}
using(var context = new SampleDataContext(model))
{
 // problem occurs here, when I try to open a second context.
}

I have actually been able to make this work correctly if I add the line

MultipleActiveResultSets=True

To my connection string; But this seems fishy to me. I don't think this should be required, or I would see it in a lot more sample applications. Can someone explain to me what is going on here and what I should do to correctly fix it?