谢谢你的关注,其实是利用了Delphi5的例程Pooler,将DM中放入TADOConnection,TADOQuery,TDataSetProvider,Web(CGI)程序通过DCOM连接中间层。在例程中加入了判断,如果连接数据库的信息改变了就重新创建,否则看已存在的是否在使用,在用就重建,没在使用就连接到该线程。
function TPoolManager.LockRDM(DBSetCode:String;CanCreate:Boolean): IPooledRDM;
var
i: Integer;
begin
Result := nil;
if WaitForSingleObject(FSemaphore, Timeout) = WAIT_FAILED then
raise Exception.Create('Server too busy');
for i := 0 to FRDMList.Count - 1do
begin
if GetLock(i,DBSetCode) then
begin
Result := PRDM(FRDMList).Intf;
Exit;
end;
end;
if CanCreate then
for i := 0 to FRDMList.Count - 1do
begin
if GetLock(i,DBSetCode) then
begin
Result := PRDM(FRDMList).Intf;
Exit;
end;
end;
if (CanCreate) and (FRDMList.Count < MaxCount) then
begin
Result := CreateNewInstance;
Result.ConnectADOC(DBSetCode);
end;
if Result = nil then
raise Exception.Create('Unable to lock RDM');
end;
procedure TPoolManager.UnlockRDM(var Value: IPooledRDM);
var
i: Integer;
begin
for i := 0 to FRDMList.Count - 1do
begin
if Value = PRDM(FRDMList).Intf then
begin
ReleaseLock(i, Value);
break;
end;
end;
end;