DataReader Question

  • Thread starter Thread starter Paul W
  • Start date Start date
P

Paul W

What is the best way to fix this...

I was given a piece of code that uses a datareader to pass data.
Function X calls Function Y and Function Y returns a datareader with
the data that Function X needs.

Function X closes the datareader when it is done, but the connect in
Function Y is never closed, no hook is passed from Y to let X close it.

What is the best way to fix this? Pass a hook to X so X can close the
connection declared in Y? Is there another way (without changing a lot
of code)?

Thanks,

Paul W
 
In function X, you can have the Command pass CommandBehavior.CloseConnection
to the ExecuteReader method. This will then close the connection when the
reader is closed.

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
I have that and the connection seems to stay open, maybe I missed a
DataReader.close somewhere...

Thanks,

Paul W
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top