2

Well, I managed get the delegate driver to set up properly, but connection pooling is still giving me a lot of trouble.

From the descriptions given in the documentation, it appears that connection pooling should work like this:

  • Set up the DBXPool driver delegate on a single, global Connection object
  • Use this Connection object for all calls into the database
  • Each DB call will get automagically routed through the delegate driver into a connection that's unique to its thread, owned by the connection pool.

In practice, I'm finding that everything seems to still be handled by the global Connection object, leading to all sorts of strange race conditions and crashes when I try to run DB queries from multiple concurrent threads.

In case it's relevant, I don't have many DBX-specific components defined; I generally run queries by calling the Connection.Execute method.

Any idea what I'm doing wrong? Am I missing a step somewhere, or do I have a bad understanding of how the DBXPool delegate driver works?

4

1 回答 1

2

Delphi comes with a sample project DelegatesSample. On my machine it is located under \Documents\RAD Studio\8.0\Samples\Delphi\Database\dbExpress\Delegates.

Each connection in the pool has it's own TDBXConnection object. In sample source code each connection is created by call to TDBXConnectionFactory.GetConnectionFactory.GetConnection().

As you know of course, each query in a thread should have it's own connection object.

Felix Colibri has also great article about Delphi DBX4 programming. There he describes amongst other topics also pooling database connections using a pooling delegate driver.

At least these samples helped mine understanding how connection pooling works!

于 2012-07-13T10:48:07.690 回答