views:

175

answers:

1

Hay, My system needs to execute several major SQL`s (on Oracle DB) using the same connection (asynchronous).

What`s the best practice for this issue? 1. open single connection and execute every SQL statement on different thread (does it thread safe?) 2. create new connection and “open + close” it for every SQL statement

Thanks, Hec

+2  A: 

We've been calling Oracle SQL statements on multiple threads, and this is probably best, if your DB can handle the load and won't be the bottleneck anyway. HOWEVER, I think you need to create the connection on the thread that will be issuing the SQL command. You can (and probably should) also use connection pooling so your connections will be reused, rather than being re-established (and Oracle seems to be fine with re-using these from one thread to another).

Andy Jacobs
what do you mean by using "Connection Pooling"? the ODP.NET has built in connection pool (which I only need to config it on my connection string). right?
Avi K.
Yes, that's the connection pooling I was referring to. It was just a bit unexpected (for me) that ODP.NET forced me to open each connection in the thread that was going to use it, but itself would re-use connections (in its own connection pooling) across threads. But I suppose this is enforced to help ensure thread safty of the client code.
Andy Jacobs
by the way, currently i`m using only one connection and passing it to all the thread and it works just fine... anyway - i think that its better to open connection and "close" it afterwords on each thread. Thanks for the answer!
Avi K.