views:

81

answers:

4

Hi,

First up, I understand why it is good practice to close server database connections as soon as possible.

I am developing a program that will contain a local database (5 tables ~ 200 columns), it may grow to a few thousand rows (so doubt it will be too much of an overhead). My first thought was to keep the local db connection until the program is closed.

Can you please confirm if this will be ok or highlight reasons why I would not want to do this?

A: 

Is there any particular reason why you want to keep the connection open? What is it that you want to achieve by doing that?

If it is a single user application, where the database will serve one single instance of the program, theoretically I guess it would not hurt. However, if your application should turn into an application that is used by several people running against the same database, it may become an issue.

I would say; stick to recommended practice, unless you have really good reasons not to.

Fredrik Mörk
+1  A: 

ADO.NET in conjunction with most database engines provide automatic connection pooling in the background by default. There's absolutely no need to keep the connection open as ADO.NET will do that for you anyway and give it back when you reopen it. Just close it, one less thing to worry about.

DrJokepu
A: 

there is no reason for this

A: 

@Fredrik Yes it would be a single user connection to a localDB on their user profile. Only reason I thought of keeping it open would be to avoid possible Exceptions when re-connecting but I think the connection pooling response sums it up so I am happy to go ahead and close when finished.

@DrJokepu Cheers

chebron