Open and close connection or leave open

bluep651

Member
Joined
Feb 16, 2009
Messages
7
Programming Experience
Beginner
Is it more efficient for an enquiry program to open a connection and keep it open until the program ends, or open and close a connection each time the data needs refreshing (when the user requests it, so could be frequent, or not, as the case may be)?

SQL Server btw

TIA,

blue
 
Microsoft recommend you open, do work, and close. Additionally, because of connection pooling done by the .NET framework, you arent actually opening and closing TCP connections like you might think you are; youre just leasing and returning connections from/to the pool. Keeping a connection "open" can only serve to screw this mechanism up.

In short, do what Microsoft say to do (unless you've deliberately turned off pooling, in which case O/C will have a horrendous performance hit) :)
 

Latest posts

Back
Top