Multithread Unidac UniConnection
-
- Posts: 3
- Joined: Sat 27 Jun 2015 21:33
Multithread Unidac UniConnection
hello,
it is posible using unidac to make multithread like
Multithreaded Delphi Database Queries with dbGo (ADO)
i want use it but using unidac..
thank you..
it is posible using unidac to make multithread like
Multithreaded Delphi Database Queries with dbGo (ADO)
i want use it but using unidac..
thank you..
Re: Multithread Unidac UniConnection
UniDAC is thread-safe, so you can use it for development of multi-threaded applications.
Re: Multithread Unidac UniConnection
Hi MaximG,MaximG wrote:UniDAC is thread-safe, so you can use it for development of multi-threaded applications.
Is there some documentation or an example somewhere?
Which parts can be threaded? Does each thread need its own TUniconnection and Transaction?
Re: Multithread Unidac UniConnection
When using UniDAC for creating multithreaded applications, you can use approaches similar to the ones described in the "Multithreaded Delphi Database Queries with dbGo (ADO)" article.
At this, you should take into account, that the correct solution will be to use a separate connection (the TUniConnection component) in each thread. In this case, your application will be thread-safe. You can have infinite amount of queries running through one connection in one thread, but you must not run several queries from several threads through one connection.
At this, you should take into account, that the correct solution will be to use a separate connection (the TUniConnection component) in each thread. In this case, your application will be thread-safe. You can have infinite amount of queries running through one connection in one thread, but you must not run several queries from several threads through one connection.
Re: Multithread Unidac UniConnection
Thanks, a bit more on Transactions please.MaximG wrote:In this case, your application will be thread-safe.
This assertion shows that one Transaction is active even though I did not set one up:
Code: Select all
self.Connection.DefaultTransaction := nil;
Assert(self.Connection.TransactionCount=0);
Re: Multithread Unidac UniConnection
Please clarify the transaction behavior you need to be implemented. Also, specify the database used in your demo sample.
Re: Multithread Unidac UniConnection
Hi MaximG,MaximG wrote:Please clarify the transaction behavior you need to be implemented. Also, specify the database used in your demo sample.
It's really not about what I need to implement but more about what happens automatically when a uniConnection is created inside a thread. In this code which runs inside the thread I create a new uniConnection to a Firebird db and when I execute it all worked.. Now FB always requires a transaction so I tested with the code I posted earlier and sure enough a Transaction already exists in that uniConnection. So I need to ask, is that Transaction thread safe?
Code: Select all
Con := TUniConnection.Create(nil, Data.ConnectString);
try
Con.Connect;
Rsl := Con.ExecProc(Data.ProcName, Data.ParamsIn);
Con.Close;
finally
Con.Free;
Dispose(Data);
end;
Re: Multithread Unidac UniConnection
Yes, you are right. InterBase/Firebird requires an active transaction for any operation with data. So, if you set
even explicitly, then TUniConnection will use an active transaction. This internal transaction is created separately for each TUniConnection and is thread-safe.
Code: Select all
Self.Connection.DefaultTransaction := nil;
Re: Multithread Unidac UniConnection
Hi ViktorV,ViktorV wrote: This internal transaction is created separately for each TUniConnection and is thread-safe.
Perfect, that sure makes things simple

Fred
Re: Multithread Unidac UniConnection
If you have any questions during using our products, please don't hesitate to contact us - and we will try to help you solve them.