Link to home
Start Free TrialLog in
Avatar of marklye
marklye

asked on

Best Practice - Keep SQL connection open, or open new each time?

Hi there

Im developing an app in vb .net that uses a SQL database.  My question is, is it best to publicly declare and keep open an SQL connection, or best to open and close the connection each time needed?

Users of my app could potentially keep the app open for days at a time (yes, they're not very computer savvy).

So, what do you think is best option?

Hope my question isnt too vague...appreicate your help

Cheers
Mark
ASKER CERTIFIED SOLUTION
Avatar of chapmandew
chapmandew
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also regarding to security it's better to always close the connection. The time that it take to open and close doesn't justify to leave it open.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That isn't necesaarrily true....connections will time out if you have them in use and they are not able to get data from the db...otherwise they will wait for the next command to execute.

Tim
Tim, that is the command timeout. Unused connections time out, otherwise all database servers would have to be restarted regularly to keep working.
Avatar of marklye
marklye

ASKER

Thats great thanks guys...Ive split the points

Cheers
Mark