base {System.SystemException} = {"Invalid attempt to call FieldCount when reader is closed."}

Topics: Data Access Application Block
Sep 4, 2009 at 1:14 AM

I have the oddest error and have no idea what to do about it. I have been using Ent Lib 4.1 for a long time and this code has always worked but for this instance it is not working.

I have a ObjectDataSource that calls this method in my DAL - GetSubSetSortedByID()

Here is the code;





postPostAttachment =


(IDataReader dataReader = db.ExecuteReader(dbCommand))while (dataReader != null && dataReader.Read())new PostPostAttachmentInfo(dataReader);//Add an postPostAttachment to the postPostAttachments collection.




The stored proc works and returns data but in my C# I always end up with Count = 0 and this error message - base {System.SystemException} = {"Invalid attempt to call FieldCount when reader is closed."}

I have no idea why my DataReader is closed all of a sudden. Any help would be greatly appreciated.

Sep 4, 2009 at 5:43 AM
Edited Sep 4, 2009 at 5:47 AM


Do you close the reader explicitly somewhere in your code? I'm just wondering whats inside the constructor of the  PostPostAttachmentInfo class, Would you mind posting it?

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.