InvalidOperationException: There is already an open DataReader associated with this Command which...
When I try to run 2 ExecuteQueryDynamic()
's, I get:
InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
sample code:
//works ExecuteQueryDynamic("SELECT TOP 1 * FROM Customers").Dump(); //doesn't work ExecuteQueryDynamic("SELECT TOP 1 * FROM Customers").Dump();
reference: https://stackoverflow.com/a/27750602/185123
Comments
I can't reproduce this in LINQPad 6 or LINQPad 5. Is it a standard LINQ-to-SQL connection? Is there any other info you can provide?
It seems to make doing the dump in between
//works
var ret = ExecuteQueryDynamic("SELECT TOP 1 * FROM Customers");
ret.Dump();
//doesn't work
var ret2 = ExecuteQueryDynamic("SELECT TOP 1 * FROM Customers");
ret2.Dump();
This issue is reproducible in Results to Data Grids mode.
You can solve this by iterating the IEnumerable manually, to make sure each reader is executed once during execution.