How to determine if MyConnection busy

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Red_Romanov
Posts: 2
Joined: Fri 07 Sep 2018 06:59

How to determine if MyConnection busy

Post by Red_Romanov » Fri 07 Sep 2018 07:20

I am very surprised no one have asked this question yet. How do I know if MyConnection is currently busy?

My application needs MyConnection to ping to the server to keep the connection alive, so I set up a timer for this. While another part of my application needs to request data from the server for for a lengthy period, using Ping command in the middle of this process causes exceptions like "net packet out of order" or "SQL statement doesn't return rows".

I understand that one MyConnection cannot run multiple commands/threads at the same time, but I don't know how to determine if the MyConnection is busy so I can prevent this problem.

ViktorV
Devart Team
Posts: 2387
Joined: Wed 30 Jul 2014 07:16

Re: How to determine if MyConnection busy

Post by ViktorV » Fri 07 Sep 2018 12:02

It's impossible to detect whether MyConnection is currently busy or not.
MyDAC is thread-safe, but the restriction is that you cannot use one connection (the TMyConnection component) in several threads, and you should use a separate connection in each thread.
You can have infinite amount of queries running through one connection in one thread, but you should not run several queries from several threads through one connection.
If you are using a multi-threaded application, then a separate connection (the TMyConnection component) per thread must be used.

Red_Romanov
Posts: 2
Joined: Fri 07 Sep 2018 06:59

Re: How to determine if MyConnection busy

Post by Red_Romanov » Mon 10 Sep 2018 02:52

I need this connection for requesting data, and I need this same connection to ping every few seconds to keep it alive when the user is idle. I can't use another connection for this because timeout clocks are separated for each one.

ViktorV
Devart Team
Posts: 2387
Joined: Wed 30 Jul 2014 07:16

Re: How to determine if MyConnection busy

Post by ViktorV » Mon 10 Sep 2018 15:22

As we already wrote, MyDAC is thread-safe, but the restriction is that you cannot use one connection (the TMyConnection component) in several threads, and you should use a separate connection in each thread.
If your application architecture is such that you use one TMyConnection instance in different threads, you need to make a thread-safe access for this instance: for example, to call the Ping method with the help of critical sections.
If you mean something else, please write us in more detail.

Post Reply