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
 
Back
Top