open cn for page or each stmt - ASP.NET?

  • Thread starter Thread starter dan
  • Start date Start date
D

dan

I'm trying to figure out the best practice for opening db
connections on an asp.net page. I have seen this done by
opening one connection for the page and using it for all
commands, and I have seen the connection open and closed
each time you run a command.

What is the best practice here? Is making the actual
connection each time slower than just keeping it open the
whole time, or is it better to free up database resources
in between commands?
 
Consider that most of the time when you "open" a Connection, ADO.NET simply
sets a pointer to a suitable idle connection in the Connection pool. Yes,
this takes a little time but permits better use of available connections.
When you close a connection, it's not really closed but returned to the pool
for other instances to use.
If your ASP program executes several queries without user intervention then
it makes sense to reuse the open connection, but if your logic includes user
interaction, then you need to close and release the connection.

hth

--
____________________________________
Bill Vaughn
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Back
Top