Do I need to close Reader if I close the Connection?

T

tshad

I have a situation where I could

Try
Open a Connection
ExecuteReader
Close Reader
Catch

may not happen - Possible if this a Timer in a Windows Service

End Try

The problem is that the connection and/or the Reader may be open when I get
to the "Open a Connection".

The Connection and Reader are Container objects in VS and are Global.

If the Sql Server is down, I may get bounced out of the Openning Connection
or ExecuteReader statement and never get to the Catch because the delay
waiting for a response may be longer that the Timer delay.

So when I come back, how do I handle the Connect and Reader before the "Open
a Connection" code?

I know I could do something like:

if SqlConnection1.State = "Open" then Close it

But what about the Reader?

Do I need to do something about it? I don't know if it is open or not.

Thanks,

Tom
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top