Member Avatar for starsinthesky

hi there!

just wanna know why it is necessary to close the DataReader and database connection after use?

what are the effects of just leaving it open?

Recommended Answers

All 3 Replies

I believe there is some!!! but in my opinion the main one is performance.

Use CommandBehavior.CloseConnection when using datareaders.

This will close the database connection when the reader is closed.

You need an Open connection when dealing with datareaders since it fetches only one record at a time

Server resources are precious. Opening a database connection counts you are the user and database create a new thread to serve you. A new thread is alive till user send disconnect command through Close() method.

I think you got it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.