So that is not the same then as the method returning null. Those are 2 very
very very different things.
You are not showing what is after the 'try' block, but I suspect you have a
finally block afterwards, that is closing the connection.
A datareader requires an open and active connection to the database, since
it retrieves one row at a time. It is usually not a good idea to return
datareaders to callers outside the class, since they have to be responsible
for closing the connection - and if the developer forgets, you get
connection leaks.
You should fill a datatable instead, and return that.
"JJ" <(E-Mail Removed)> wrote in message
news:5DA13617-2125-4740-87D3-(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
>> news:C48F3FDF-6260-4510-A208-(E-Mail Removed)...
>> > 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
>>
>>
>>
|