DataPortal.Fetch failed (There is already an open DataReader associated with this Command which must be closed first.)

DataPortal.Fetch failed (There is already an open DataReader associated with this Command which must be closed first.)

Old forum URL: forums.lhotka.net/forums/t/7780.aspx


ludwigs3rd posted on Tuesday, October 13, 2009

This happens whenever the client crashes (test case) and using WCFHost setup like in PTracker. I've implemented Dispose() in the DAL like in Rocky's C# 2008 BO page 550 but that doesn't seem to fix the issue. The only way I can get around this issue is by restarting the server hosting the WCFHost. I appreciate any suggestions anyone can offer.

RockfordLhotka replied on Tuesday, October 13, 2009

You are saying that a db connection on the application server is being left open (or something) because the client crashed? So the client crash is echoing through the WCF connection to the server or something?

 

ludwigs3rd replied on Wednesday, October 14, 2009

I may have worded that incorrectly. So we are purposefully creating a condition on the client where the DAL throws an exception. But looking at the code, since the SafeDataFeader is thrown back to the parent object (from the DAL to populate the fields/properties) I guess I should be explicitly closing it? I didn't see an example showing that in the book (maybe I missed it). Is explicitly closing the SafeDataReader recommended or necessary?

whelzer replied on Wednesday, October 14, 2009

You can use ;MultipleActiveResultSets=True" in you connection string

ludwigs3rd replied on Wednesday, October 14, 2009

Interesting, that worked like a charm. Thanks for your suggestion! Should I still be explicitly closing the DataReader?

JoeFallon1 replied on Wednesday, October 14, 2009

Yes.

If dr IsNot Nothing Then dr.Close
If cnn IsNot Nothing Then cnn.Close

Joe

Copyright (c) Marimer LLC