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.
How to determine if MyConnection busy
Re: How to determine if MyConnection busy
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.
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.
-
- Posts: 2
- Joined: Fri 07 Sep 2018 06:59
Re: How to determine if MyConnection busy
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.
Re: How to determine if MyConnection busy
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.
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.