Opening a Connection

J

Jason MacKenzie

I'm looking at this application I've written and it seems kind of silly how
many times I open and close a connection to the database.

Is there a best practice as far as this is concerned? If I open a connection
in the page load event is there any way I can be sure that its closed off?

Any thoughts are appreciated,

Jason
 
K

Kevin Spencer

Is there a best practice as far as this is concerned? If I open a
connection
in the page load event is there any way I can be sure that its closed off?

The best way to make sure that the connection is closed is to close it. Make
that the only way.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
J

Jason MacKenzie

That's what I always do. Just wanted to see if there was a better way.
Thanks guys.
 
E

Eliyahu Goldin

You will save yourself from many problems if you close the connection after
every data access operation. It is the recommended practice in ADO.NET.
Put your data access code into try..finally blocks and close the connection
in the finally.

Eliyahu
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top