I have a RO/DA DLL server, using AnyDAC, which isn’t unloading and I’ve been instructed to close and release all connections in the pool. This code won’t compile and I’m struggling to get anywhere else:
var
ida : IDAConnectionPool;
C : TDAConnection;
iC: IDAConnection;
I: Integer;
begin
ida := ConnectionManager as IDAConnectionPool;
for I := 0 to ConnectionManager.Connections.Count - 1 do
begin
C := ConnectionManager.Connections.Connections[0];
iC := C as IDAConnection; //<-- invalid operate
if iC.Connected then
iC.Close;
ida.ReleaseConnection(iC);
end;
ConnectionManager.ClearPool; //<-- wiki says this does not close connections.
end;
Hello,
ClearPool closes all cached connections (TDAConnectionManager.PoolingEnabled should be True).
If this value is Fasle that connection is closed after each service datamodule call.
What TDAConnectionManager.PoolingEnabled value do you use?
I use connectionmanager.poolingenabled := true. I read in the wiki that the ClearPool does close the connection. I suppose my question should be, is it necessary to close each open connection or is ClearPool sufficient.
I should say again that this request is being made as part of another issue that affects RODA DLL Servers with the AnyDAC driver, and I have been asked to close and release all connections before unloading the DLL Server).
Also, I can’t see why I can’t cast a TDAConnection as an IDAConnection to be able to test whether the connection is Active or to call Close?
Hello,
If you use connectionmanager.poolingenabled := true that ClearPool closes and frees all connections.
procedure TDAConnectionManager.ClearPool;
var
i: Integer;
list: TList;
begin
list := fConnectionCache.LockList;
try
for i := list.Count -1 downto 0 do begin
TCachedConnection(List[i]).Connection.ConnectionPool := nil;
TCachedConnection(List[i]).Free;//<==Closes and frees connection
end;
Dec(fTotalConnections, list.Count);
list.Clear;
finally
fConnectionCache.UnlockList;
end;
end;
The TDAConnection class just holds information about connections: the name, the description, the type,
the connection string and other information.
The IDAConnection interface represents an individual connection to a database and is usually obtained from the TDAConnectionManager
component and will be implemented by different classes depending on the database driver you are using.