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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Tim, that is the command timeout. Unused connections time out, otherwise all database servers would have to be restarted regularly to keep working.
ASKER
Thats great thanks guys...Ive split the points
Cheers
Mark
Cheers
Mark