Opening a Connection

  • Thread starter Thread starter Jason MacKenzie
  • Start date Start date
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
 
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.
 
That's what I always do. Just wanted to see if there was a better way.
Thanks guys.
 
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

Back
Top