Page 1 of 1

Multithread Unidac UniConnection

Posted: Wed 05 Aug 2015 13:33
by yayaretina
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..

Re: Multithread Unidac UniConnection

Posted: Thu 06 Aug 2015 08:37
by MaximG
UniDAC is thread-safe, so you can use it for development of multi-threaded applications.

Re: Multithread Unidac UniConnection

Posted: Thu 13 Aug 2015 20:46
by FredS
MaximG wrote:UniDAC is thread-safe, so you can use it for development of multi-threaded applications.
Hi MaximG,

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

Posted: Tue 18 Aug 2015 08:29
by MaximG
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.

Re: Multithread Unidac UniConnection

Posted: Tue 18 Aug 2015 19:54
by FredS
MaximG wrote:In this case, your application will be thread-safe.
Thanks, a bit more on Transactions please.

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);
Can I just ignore that? Are whatever default transactions the connection holds thread safe themselves?

Re: Multithread Unidac UniConnection

Posted: Thu 20 Aug 2015 09:46
by MaximG
Please clarify the transaction behavior you need to be implemented. Also, specify the database used in your demo sample.

Re: Multithread Unidac UniConnection

Posted: Thu 20 Aug 2015 17:34
by FredS
MaximG wrote:Please clarify the transaction behavior you need to be implemented. Also, specify the database used in your demo sample.
Hi MaximG,

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

Posted: Fri 21 Aug 2015 08:23
by ViktorV
Yes, you are right. InterBase/Firebird requires an active transaction for any operation with data. So, if you set

Code: Select all

Self.Connection.DefaultTransaction := nil;
even explicitly, then TUniConnection will use an active transaction. This internal transaction is created separately for each TUniConnection and is thread-safe.

Re: Multithread Unidac UniConnection

Posted: Fri 21 Aug 2015 16:34
by FredS
ViktorV wrote: This internal transaction is created separately for each TUniConnection and is thread-safe.
Hi ViktorV,

Perfect, that sure makes things simple :D

Fred

Re: Multithread Unidac UniConnection

Posted: Thu 27 Aug 2015 10:35
by ViktorV
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.