matsgefvert wrote:The problem goes down to the libmysql API. A single connection is instantiated using memory buffers inside libmysql, and each query uses this connection buffer or handle to process queries back and forth. There is no problem whatsoever with allowing hundreds of queries to use the same connection, as long as they are properly serialized - that is, as long as all access happens from one thread, you're fine.
If you're using multiple threads, then things will go wrong rather quickly, and libmysql can start producing nasty errors like "connection to server lost", "invalid handle", "table nn does not exist" and so on.
For your situation, I see no problem with lots of ZQuery objects in different datamodules using the same ZConnection object, even in DLL's, as long as it can be guaranteed that you're not running multiple threads.
As soon as you have two threads running, you either need to serialize access to queries/connections through critical sections, or instantiate one ZConnection per thread and tie the respective ZQuery objects to the thread-specific ZConnection.
/ Matt
Thanks, that's what I wanted (or rather not wanted, but so be it) to hear.
We have problems with running multiple apps using the same ZConnection.
This is a simplistic schematic of our app:
Executable --> DLL1 --> DLL2 --> DLL3
A record/struct is passed from the executable up to the last DLL. If you close the APP in the last DLL (DLL3), then DLL2 will become active again.
We wanted to include the ZConnection-component in our record/struct, but it seems this isn't gonna work with Zeos & MySQL (mostly because of MySQL).
We knew of the problem, but I had a little hope that someone else solved the problem. Too bad.