Re: ADOQuery in thread hangs



Now a LONG time after the thread "hung" it suddenly popped up an error
message saying "System error 1309" and "A call to an OS function failed"
+ $2[51F1A494]{rtl100.bpl } SysUtils.SysUtils.RaiseLastOSError (Line
16275, "sysutils.pas" + 7) + $2
+ $5[51F1A41D]{rtl100.bpl } SysUtils.SysUtils.RaiseLastOSError (Line
16262, "sysutils.pas" + 0) + $5
+ $0[51F40BB0]{rtl100.bpl } Classes.Classes.StdWndProc (Line 11572,
"classes.pas" + 8) + $0
+ $6A[77D38731]{USER32.dll } GetDC + $6A
+ $14A[77D38811]{USER32.dll } GetDC + $14A
+ $122[77D389C8]{USER32.dll } GetWindowLongW + $122
+ $A[77D396C2]{USER32.dll } DispatchMessageA + $A

Can this help?


"Mikael Lenfors" <mikael@xxxxxxxxxx> wrote in message
news:45640064$1@xxxxxxxxxxxxxxxxxxxxxxxxx
I think I have localiced where the problem begins...

In my main program (not the thread) i have the following code. The
EditSchedulesForm is a maintenance form and it adds a procedure hook for
all insert events. When an insert triggers it sets some default values
including an ID which i get through another functioncall to
GetNextScheduleId. This is where it all goes wrong! As soon as this
GetNextScheduleId is executed the thread!! stops working with the error i
mentioned earlier. If I in GetNextScheduleId just put a "Result := 100;
Exit;" then it works.
The really strange thing is that my main program works all the time, also
after the code below s run.

-- From maintenance form

Procedure TEditSchedulesForm.FormShow(Sender: TObject);
DBForm.ADOQuery.AfterInsert := InsertRecord;

Procedure TEditSchedulesForm.FormDestroy(Sender: TObject);
DBForm.ADOQuery.AfterInsert := Nil;

Procedure TEditSchedulesForm.InsertRecord(DataSet: TDataSet);
Begin
DBForm.ADOQuery.FieldByName('ScheduleID').AsInteger :=
DBForm.GetNextScheduleId;
DBForm.ADOQuery.FieldByName('ScheduleCreationDate').AsDateTime := Now;
DBForm.ADOQuery.FieldByName('ScheduleChangeDate').AsDateTime := Now;
End;

--- From DBForm

Function TDBForm.GetNextScheduleId: Integer;
Begin
Result := 0;
Try
ADOQuery3.Close;
ADOQuery3.SQL.Clear;
ADOQuery3.SQL.Add('Select Max(ScheduleId) As MaxId');
ADOQuery3.SQL.Add('From Schedules');
ADOQuery3.Open;
If ADOQuery3.RecordCount = 1 Then
Result := Max(1, ADOQuery3.FieldByName('MaxId').AsInteger + 1)
Else
Result := 1;
LogForm.Log(1, 'Retreiving next free Schedule ID as ' +
IntToStr(Result), 0);
Except
On E: Exception do
Begin
LogForm.Log(4, 'Failed retreiving next free schedule Id!', 0);
LogForm.LogSQL(0, ADOQuery3.SQL, 0);
LogForm.Log(0, 'Error: ' + E.Message, 0);
End;
End;
ADOQuery3.Close;
End;


"Mikael Lenfors" <mikael@xxxxxxxxxx> skrev i meddelandet
news:4563ec72$1@xxxxxxxxxxxxxxxxxxxxxxxxx
Yes I create a TADOQuery local to the thread. In the thread I don't have
any ADOConnection, I just use a connectionstring directly in the
ADOQuery.

Mikael


"Brian Bushay TeamB" <BBushay@xxxxxxxxx> skrev i meddelandet
news:n897m2hao5o1ff76lq199v79aav5oqtvtu@xxxxxxxxxx
Hello!

Having a real nightmare problem at the moment. In my main program I have
a
ADOConnection and several associated ADOQuerys. They are all connected
to an
Access file.
Then I have a TThread containing it's own ADOQuery, connecting to the
same
Access file doing some selects. I can run the thread as many times as I
want
without any problem. If I then do an Insert statement in the main
program a
strange thing happenes. The next time I'm running the thread it DIES at
the
first line where I do ADOQuery.SQL.Add...

ADOQuery.Close;
ADOQuery.SQL.Clear;
ADOQuery.SQL.Add('Select * From Units Where UnitID = ' +
IntToStr(UnitRecord.UnitID));
ADOQuery.Open;

The above is sample code from the thread, if I trace it and press F8 at
the
Add line it just dies there, no exceptions what so ever.

Running Win XP Pro and Delphi Studio 2006

Please any ideas?


When you use a thread you need to create the TadoQuery as well as its
connection
in the thread. You didn't indicate if that is what you are doing.
--
Brian Bushay (TeamB)
Bbushay@xxxxxxxxx










.



Relevant Pages

  • Re: ADOQuery in thread hangs
    ... EditSchedulesForm is a maintenance form and it adds a procedure hook for all ... I just use a connectionstring directly in the ADOQuery. ... Add line it just dies there, ...
    (borland.public.delphi.database.ado)
  • Re: ADOQuery in thread hangs
    ... ADOConnection, I just use a connectionstring directly in the ADOQuery. ... Add line it just dies there, ...
    (borland.public.delphi.database.ado)
  • Re: Updating Database
    ... the register is very easy to maintain in VBNet, so you can look if there is ... a connectionstring in that and when not, just ask the user for the place ... the load event, that makes it possible to set your access file everywhere, ...
    (microsoft.public.dotnet.framework.adonet)