ADOConnection fail after a while in TThread
- From: "Mikael Lenfors" <mikael@xxxxxxxxxx>
- Date: Mon, 17 Oct 2005 13:42:46 +0200
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;
.
- Follow-Ups:
- Re: ADOConnection fail after a while in TThread
- From: AlexB
- Re: ADOConnection fail after a while in TThread
- From: Tom Hagen
- Re: ADOConnection fail after a while in TThread
- From: Martin James
- Re: ADOConnection fail after a while in TThread
- Prev by Date: Re: Thai Characters not pulling from Access, showing ????????
- Next by Date: Re: Bulk Insert - Help
- Previous by thread: [Q] Dynamically built Locate calls on compound fields don't work for some reason
- Next by thread: Re: ADOConnection fail after a while in TThread
- Index(es):
Relevant Pages
|