This is my code:
procedure TfrmServerMain.CmdHndler_GetOrderProdDatesCommand(ASender: TIdCommand);
begin
if Assigned(ASender.Params) then
with TADOQuery.Create(nil) do
begin
Connection := ADOConnection1;
SQL.Clear;
SQL.Add('SELECT *');
SQL.Add('FROM DoneOperations');
SQL.Add('WHERE OrderID = ' + ASender.Params[0]);
SQL.Add('ORDER BY DoneDate');
try
Open; // issued line
if RecordCount = 0 then
begin
ASender.Context.Connection.Socket.WriteLn(FloatToStr(MaxDateTime), TIdTextEncoding.UTF8);
ASender.Context.Connection.Socket.WriteLn(FloatToStr(MaxDateTime), TIdTextEncoding.UTF8);
end
else
begin
First;
ASender.Context.Connection.Socket.WriteLn(
FloatToStr(FieldByName('DoneDate').AsDateTime));
Last;
ASender.Context.Connection.Socket.WriteLn(
FloatToStr(FieldByName('DoneDate').AsDateTime));
end;
except
Log(ltError, 'Exception while sending Orders start/end date');
ASender.Context.Connection.Socket.WriteLn('error');
ASender.Context.Connection.Socket.WriteLn('error');
end;
Close;
Free;
ASender.Context.Connection.Disconnect;
end;
end;
everything is ok, and code run correctly. but sometimes (20% of times) randomly when application execute Open;
line, causes access violation error.
the SQL statement is tested separately, and works without any error in any condition.
f.e.: SELECT * FROM DoneOperations WHERE OrderID = 35 ORDER BY DoneDate
OSs that I test: Windows7, Windows Server 2008.
I can't handle this, or find it's cause. thanks from your help.