ADOConnection fail after a while in TThread



Hello!

I have a problem when using ADO components in a thread. My program starts
about 150 threads for communication with our stores. Each thread creates
it's own ADOConnection and ADOQuery components. When all 150 threads have
terminated it starts all over again (creating 150 new threads). All this
works perfectly until suddenly (after about 20-100 cycles) it fails to
connect to the store databases and in every thread I get an exception in
ConnectDB. Below I show the essential part of the code. If I stop the
program and restart it, it works fine again for 20-100 cycles.
One strange thing is that I have a ADOConnection in the main thread as well.
When this thread problem occures also this ADOConnection fail to connect, to
a completely different datasource.

Any ideas?

Regards, Mikael

------------
Type
TMyThread = class(TThread)
private
ADOConnection: TADOConnection;
ADOQuery: TADOQuery;
------------
Procedure TMyThread.Execute;
Begin
ADOConnection := TADOConnection.Create(Nil); <--- is it Ok to use
Nil here?
ADOQuery := TADOQuery.Create(Nil);
ADOQuery.Connection := ADOConnection;
If ConnectDB Then
Begin
----Do some work with the ADOQuery
ADOQuery.Close;
ADOConnection.Close;
End;
ADOQuery.Free;
ADOConnection.Free;
End;
------------
Function TMyThread.ConnectDB: Boolean;
Begin
Result := False;
Try
ADOConnection.Close;
ADOQuery.Close;
ADOQuery.CursorType := ctOpenForwardOnly;
ADOQuery.CommandTimeout := 5 * 60; // 5 min
ADOConnection.CommandTimeout := 5 * 60; // 5 min
ADOConnection.ConnectionString := <my connection string, one for each
store>;
ADOConnection.ConnectionTimeout := 5;
ADOConnection.LoginPrompt := False;
ADOConnection.CursorLocation := clUseClient;
ADOConnection.KeepConnection := False;
ADOConnection.Attributes := [xaCommitRetaining,xaAbortRetaining];
ADOConnection.Connected := True;
Result := True;
Except
ADOStoreConnection.Connected := False; <- When the problem starts,
this is where I go in each thread
End;
End;


.



Relevant Pages

  • Re: Milliseconds to SQL Server DateTime
    ... in SQL Server using the ADO components. ... you can store milliseconds, but not exactly, because the ... it's because SQL-Server can't store a datetime ...
    (borland.public.delphi.database.ado)
  • Connections with Gupta hangs
    ... I create a ADOConnection and then I execute an ADOQuery. ... the ADOQuery and the ADOConnection and move on to the next store. ... ADOStoreConnection.CursorLocation:= clUseClient; ...
    (borland.public.delphi.database.ado)