如何用Delphi实际的实现数据库Pooling?最好能够提供实际的例子供学习(200分)

我也想知道。
 
找本李维的ADO/MTS/COM+里面讲得很详细,我就是从他开始学起的,值得一看。
另外可以看看控制面板/管理工具/组件服务等内容,可以感受一下,里面可以设置
Pooling,水平有限,就说这么多了。
 
讲起来太复杂,还是像上面的朋友讲的找本李维的书
《Delphi 5.X ADO/MTS/Com+ 高级程序设计篇》
书上面讲的Object Pooling,DataBase Pooling 很清楚,例子也不少。
 
除了李维的书,还有别的吗?
 
odbc中可以设置某类database driver开启database pooling 功能
 
在Delphi中就有例子了(Pooler),另外再看看上面那些资料就可以了。
 
我在用BCB5做多层结构系统时,我在Server端加入了一个取得服务器IP地址的方法:GetServerIP它的参数是vIP:Variant *,IN方式,并在服务端实现了这个方法,
加入的代码如下:
*vIP="192.168.0.01";最后我注册成功。
可是在我开发客户端程序时,我用TSocketConnection
当取得它的服务时我是这样做的:
Variant* vip;
SocketConnection1->AppServer.GetServerIP(vip);
Edit1->Tex=vip;
可 是我在运行程序时出错,没有编译通过。
它说getserverIP不是variant的成员
getserverIP is not a memober of variant
请问?
我该如何去调用这个方法呢?
请各位大侠多多指教?
小生的QQ:65466700(24小时在线恭候)
MAIL: alongsun@sina.com
 
delphi/demos/midas/pooler下有一个数据库连接pooling的例子
 
李维的delphi5.x分布式多层系统一书中的第五章深入MIDAS技术有专门讨论数据库pooling技术。
 
根据我实践中的粗浅认识谈一下我对数据库Pooling的认识,不对之处望大家指正。
我们都有这样的经验:一个进程启动后,第一次连接数据库时速度会很慢,特别是在连接一些Oracle数据库的时候,连接速度慢得让人有些难以忍受;但当我们在这个进程中完成了一次连接后再重新连接数据库时,由于数据库引擎(DLL)已经被加载到调用进程的进程空间中,不用再次进行初始化工作,连接速度就会变得非常快。
在COM+系统中,客户端进程对服务器组件的调用实际上是通过dllhost.exe来完成的,它是一个代理程序,工作原理有些类似scktsrvr.exe。通过dllhost.exe来代理调用有什么好处呢?好处就在于客户端进程在释放它调用的对象的时候,实际上该组件对象的引用计数并没有变为0,该对象的直接调用者是dllhost.exe,而不是客户端进程。即使所有的客户端进程都退出了,它仍然有一个引用计数(就是dllhost.exe的那个引用,而不是客户端进程的引用),因此对象不会被释放,直到达到对话有效期(闲置关闭时间)。
仔细观察过COM+系统工作的朋友就会发现,比如把一个COM+组件的闲置关闭时间设为3分钟,当第一个客户端进程访问数据库时,速度会很慢——因为dllhost要加载组件,实例化对象,并建立数据库连接。第一个客户端进程完成调用后,其它进程再来调用组件时,访问数据库的速度就会很快——因为数据库连接已经被Pooled了。在所有客户端进程都退出后,如果3分钟后都没有新的客户端访问,dllhost.exe就会终止,同时释放掉组件对象,此时如果再有新的客户端进程调用组件,一切又得重来,因此又会变得很慢。
实际上,在不经意之间,你已经拥有了数据库Pooling,只要你把COM组件安装到COM+环境中,并辅以合适的设置即可。我在建立COM+组件的时候,一般都是选择Transactional DataModule向导建立一个COM组件,建立好程序框架、编译并安装到COM+环境中后,我就拥有一个COM+组件了。
为了取得更好的性能,在客户端数量较大的情况下还需要配置对象Pooling,但对象池的大小并不是越大越好(与线程池的效果相似)。
 
不要混淆了Object Pooling和Database Pooling
两者根本是两个概念,虽然这两个Com+都有自动支持,delphi6的帮助也写的很详细
如果不是Com+,就要自己写代码自己完成
 
对象Pooling与数据库Pooling当然是两个概念,我有把它们混在一起吗?如果我的分析没错的话,两者之间就必然存在密切的联系。
COM+是怎么实现数据库Pooling的,Delphi6的帮助中并没有写得很清楚——我是没有找到。虽然说它有自动的支持,但我想找到它究竟是怎么实现的。我上面所说的只是根据我的实践结果提出的一种分析,还没有得到权威资料的支持,大多数书籍只是说了它有这个功能,但对于这个功能在底层是怎么事现的,很少有深入详细的剖析。
希望对此有深入研究的朋友不吝赐教!
 
对象Pooling与数据库Pooling事实上毫无关联,
一个普遍的误解,是对象池化了,数据库连接也池化了,这是完全错误的!对象如果
调用结束,就应该马上把数据库连接释放!

这是delphi6帮助中对于关于Com+数据库Pooling的解释和使用方法
Opening and closing connections to a database can be time-consuming. By using a resource dispenser to pool database connections, your object can reuse existing database connections rather than create new ones. For example, if you have a database lookup and a database update component running in a customer maintenance application, you can install those components together, and then
they can share database connections. In this way, your applicationdo
es not need as many connections and new object instances can access the data more quickly by using a connection that is already open but not in use.
If you are using BDE components to connect to your data, the resource dispenser is the Borland Database Engine (BDE). This resource dispenser is only available when your transactional object is installed with MTS. To enable the resource dispenser, use the BDE administrator to turn on MTS POOLING in the System/Init area of the configuration.
If you are using the ADO database components to connect to your data, the resource dispenser is provided by ADO.
Note: There is no built-in resource pooling if you are using InterbaseExpress components for your database access.
For remote transactional data modules, connections are automatically enlisted on an object's transactions, and the resource dispenser can automatically reclaim and reuse connections.

这是delphi6帮助中对于Com+的object pooling的
Just as you can pool resources, under COM+ you can also pool objects. When an object is deactivated, COM+ calls the IObjectControl interface method, CanBePooled, which indicates that the object can be pooled for reuse. If CanBePooled is returns True, then
instead of being destroyed on deactivation, the object is moved to the object pool. It remains in the object pool for a specified timeout period, during which time it is available for use to any client requesting it. Only when the object pool is empty is a new instance of the object created. Objects that return False or thatdo
not support the IObjectControl interface are destroyed when they are deactivated.
Note: To take advantage of object pooling, you must use the 揃oth?threading model. For information on threading models, see Choosing a threading model for a transactional object.
Object pooling is not available under MTS. MTS calls CanBePooled as described, but no pooling takes place. If your object will only run under COM+ and you want to allow object pooling, set the object抯 Pooledproperty to True.
Even if an object抯 CanBePooled method returns True, it can be configured so that COM+do
es not move it to the object pool. If you install the transactional object under COM+ from the IDE, you can specify whether COM+ tries to pool the object using the COM+ page of the Type Library editor. Just select the object (CoClass) in the type library editor, go to the COM+ page, and check or uncheck the box for Object Pooling. Otherwise, a system administrator specifies this attribute using the COM+ Component Manager or MTS Explorer.
Similarly, you can configure the time a deactivated object remains in the object pool before it is freed If you are installing from the IDE, you can specify this duration using the Creation Timeout setting on the COM+ page of the type library editor. Otherwise, a system administrator specifies this attribute using the COM+ Component Manager.
这个难道还不清楚?
 
知道了,数据库连接的池化是由数据库支持的,对象Pooling是可以通过编程实现。
 
顶部