Page 1 of 1
Connection Pooling with Firebird
Posted: Thu 27 Oct 2011 14:31
by chkaufmann
I use UniDac in a Http server application with Indy. In each request (= Thread) I create a TUniConnection and free it, when the request is done.
Is it ok, if I just set the Pooling property to true before I call "Open"? If I understand the UniDac code correctly, this should work.
Or do I have to use one TUniConnection in all my threads?
cu Christian
Posted: Fri 28 Oct 2011 10:32
by AndreyZ
Hello,
UniDAC ensures that your application that works with Firebird is threadsafe. Therefore you can use one connection in several threads and you can use pooling.
Posted: Fri 28 Oct 2011 12:32
by chkaufmann
Coming from dbExpress I always thought, that I need one connection per thread.
So I create one TUniConnection in my main thread and used in all other threads with no problem?
But what about transactions? Should I use a TUniTransaction per thread and avoid the usage TUniConnection.DefaultTransaction?
Or still create one TUniConnection per thread with Pooling = True.
What happens when I have several TUniConnection's with Pooling = True
and on one I call "Close"?
cu Christian
Posted: Mon 31 Oct 2011 12:03
by AndreyZ
You can use one connection in several threads with no problems. But it's better to use its own transactions in each thread, because this way you can aviod the situation when one thread commits changes that were made in another thread. Of course, you can also have one connection in each thread to avoid this situation.
When you call the TUniConnection.Close method, this connection is removed from the pool list of available connections and it will not be used after this. Please note that it is safer not to use pooling in a multithreaded application.