如何使连接池在DBX中工作? [英] How do I make connection pooling work in DBX?
问题描述
嗯,我管理得到代理驱动程序设置正确,但连接池仍然给我很多麻烦。
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:
- 在单个全局连接对象上设置DBXPool驱动程序委托
- 使用该Connection对象用于所有调用数据库的访问
- 每个数据库调用都将通过委托驱动程序自动路由到由连接池拥有的线程所独有的连接。
在实践中,我发现一切似乎仍然被全局Connection对象处理,导致各种奇怪的竞争条件和崩溃我尝试从多个并发线程运行DB查询。
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.
如果相关,我不定义了许多DBX特定的组件;我通常通过调用 Connection.Execute
方法来运行查询。
In case it's relevant, I don't have many DBX-specific components defined; I generally run queries by calling the Connection.Execute
method.
任何想法我做错了什么?我在某处失去了一个步骤,还是对DBXPool代理驱动程序的工作有不好的理解?
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?
推荐答案
Delphi自带一个示例项目DelegatesSample。在我的机器上,它位于\Documents\RAD Studio\8.0\Samples\Delphi\Database\dbExpress\Delegates下。
Delphi comes with a sample project DelegatesSample. On my machine it is located under \Documents\RAD Studio\8.0\Samples\Delphi\Database\dbExpress\Delegates.
每个连接在池中有它自己的 TDBXConnection对象。在示例源代码中,每个连接都是通过调用 TDBXConnectionFactory.GetConnectionFactory.GetConnection()
创建的。
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也有很好的文章。在那里,他还介绍了其他主题,还使用池代理驱动程序来汇集数据库连接。
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!
这篇关于如何使连接池在DBX中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!