tags:

views:

32

answers:

2

I am using the standard Oracle driver to connect to the database, but I can't really agree with my colleagues on the lifespan of OracleConnection. Is it expensive to create? Is it thread safe? Can I reuse it between request, or should I create a new one for every request?

I would be grateful for a bit more detailed explanation which way of using it is preferred and why.

+1  A: 

It is expensive (i.e. takes a lot of time, like 1-2 seconds) to create, so you should use a connection pool. This is a very common task that has already been solved.

ammoQ
Is there a standard connection pool I could use?
Grzenio
Actually, ADO.net does that automatically for you, see http://ondotnet.com/pub/a/dotnet/2004/02/09/connpool.html
ammoQ
And is a connection thread safe?
Grzenio
Also I found this article: http://aspalliance.com/1099_Understanding_Connection_Pooling_in_NET.all. Does it mean that it will use a connection pool automagically when I just keep creating and closing connections?
Grzenio
AFAIK, connections are not threadsafe, so it's best to "create" (i.e. get from the pool) a separate connection in every thread.
ammoQ
+2  A: 

Please correct me if I am wrong, but it seems that by default the oracle driver pools connections to the database automatically. So the best practise here seems to create a new OracleConnection object before every request and dispose it after - it will be taken from the connection pool if available or created otherwise.

Grzenio