Connection Pooling with Firebird

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
chkaufmann
Posts: 82
Joined: Sat 01 Jul 2006 11:42

Connection Pooling with Firebird

Post by chkaufmann » Thu 27 Oct 2011 14:31

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

AndreyZ

Post by AndreyZ » Fri 28 Oct 2011 10:32

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.

chkaufmann
Posts: 82
Joined: Sat 01 Jul 2006 11:42

Post by chkaufmann » Fri 28 Oct 2011 12:32

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

AndreyZ

Post by AndreyZ » Mon 31 Oct 2011 12:03

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.

Post Reply