I'm not 100% positive, but I suspect your problem may be that the associated
OleDbConnection is closed. Since you are declaring the connection inside
your get method, it is only valid in this context. After GetAccRecs returns
the connection object is disposed of (and thus closed). The error message
about the closed OleDbDataReader seems consistent with this assumption.
Ideally, you should process your data inside GetAccRecs and properly close
both the reader and the connection after you're done. If you really must
process your data outside GetAccRecs, try writing it to another data
structure (maybe a DataSet) and returning a reference to this object. Theat
way you can safely close your connection before returning from GetAccRecs.
--
Kai Brinkmann [Microsoft]
Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"JJ" <JJ@discussions.microsoft.com> wrote in message
news:5D**********************************@microsof t.com...
Calling Class1 method below:
private void GetUPS(string Path, bool CNote)
{
OleDbDataReader dr = blda.GetAccRecs(Path);
try
{
while(dr.Read())
{
}
catch(Exception ex)
{
string sEMess = "";
sEMess = ex.Message;
}
}
Other Class2 Method being called:
public OleDbDataReader GetAccRecs(string aPath)
{
OleDbConnection AccCon = new
OleDbConnection(Dev_Acc_Con1);
try
{
sSQL = "SELECT * FROM Customers";
OleDbCommand cmdUPS = new OleDbCommand();
cmdUPS.Connection = AccCon;
cmdUPS.CommandType = CommandType.Text;
cmdUPS.CommandText = sSQL;
AccCon.Open();
dr2 = cmdUPS.ExecuteReader();
return dr2;
}
So this procedure gets called and returns an OleDbReader to calling
Class1.
I have checked there are records that get returned to Class1 but when Code
Statement
while(dr.Read()) gets executed, it bombs out and gives me this error:
"Invalid attempt to Read when reader is closed."
Any ideas as to why?
Thanks,
JJ
"Marina" wrote:
We can't tell you the problem if you don't post the content of the
GetRecords method. Or a reproduceable test case that shows the problem.
"JJ" <JJ@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com... > Hi,
>
> I call a class in my windows service app and in that class I access a
> method that returns an OleDbReader. Now It does have records in the
> reader
> when I step through the method but when I return to calling class the
> OleDbReader dr is null.
> What am I missing here?
>
> Class1 calls Class2.Method which returns a OleDbReader. Class1's
> OleDbReader
> is null.
>
> OleDbReader dr = Class2.GetRecords();
>
> JJ