keeping one connection to DB or opening closing per need keeping one connection to DB or opening closing per need oracle oracle

keeping one connection to DB or opening closing per need


The .NET oracle provider has built-in connection-pooling capabilities. Whenever you need a DB connection, create a new one do the work and release it immediately. The connection pooling will take care of reusing connections efficiently.

The best way to release the connection is through the using construct which will ensure that the connection is disposed, even if exceptions occur.

using(OracleConnection connection = ConnectionFactory.Create()){    connection.DoStuff();} //connection.Dispose() called here.


The best practice is to dispose connection as soon as possible. Technically connection will not be closed, just returned to the pool and will be reused by other threads.

SQL Server Connection Pooling (ADO.NET)

Quote from MSDN:

We strongly recommend that you always close the connection when you are finished using it so that the connection will be returned to the pool. You can do this using either the Close or Dispose methods of the Connection object, or by opening all connections inside a using statement.


It is ultimately about where (if anywhere) you need to throttle your connections.In a pure web app, you can't take the risk of several thousand people hitting POST at the same time. On the other hand, an internal business app may only have half a dozen users.

Can your database cope with 20 clients all making 200 calls per minute ? Will the separate threads make parallel calls to the database ?

I'd tend towards each client having its own connection pool.

Are there some clients which are more important than others ? If so, then you might want one client with 20 connections and the others with 10.

Any decent DB setup should be able to cope with a couple of hundred connections and not fall over if they all try to ping at once.