I have a situation where in Delphi I have two threads that execute a function that pings a Firebird database.
I use this to sync data from my POS (sending and receiving).
But as they run at the same time sometimes a dead lock occurs in the DB.
-
My role:
function TTPingRede(const IP: AnsiString; TimeOut: Integer = 250) : Boolean;
var
DW: DWORD;
Handle: THandle;
InAddr: IPAddr;
Arq: TextFile;
Rep: array[1..128] of byte;'
begin
try
DW := 99;
Result := False;
Handle := IcmpCreateFile;
if (Handle <> INVALID_HANDLE_VALUE) then
begin
try
TranslateStringToTInAddr(PansiChar(IP), InAddr);
DW := IcmpSendEcho(Handle, InAddr, nil, 0, nil, @rep, 128, TimeOut);
Result := (DW <> 0);
vStatusREDE_ATIVA := Result;
except
DW := 0;
Result := False;
end;
try
Dm.qStatusRede.Close;
Dm.qStatusRede.SQL.Clear;
Dm.qStatusRede.SQL.Add('UPDATE TBSINCRO001');
Dm.qStatusRede.SQL.Add('SET');
Dm.qStatusRede.SQL.Add(' STATUS_REDE_SERVIDOR = :P0');
Dm.qStatusRede.Params[0].AsInteger := DW;
Dm.qStatusRede.Prepare;
Dm.qStatusRede.ExecSQL;
if Dm.Tr_StatusRede.InTransaction then Dm.Tr_StatusRede.Commit;
except
on E: Exception do
begin
Dm.Tr_StatusRede.Rollback;
GerarLogErroSincronizar('1:FUNC ENV|'+E.Message);
end;
end;
end;
finally
IcmpCloseHandle(Handle);
end;
end;
I would like to know an implementation that I can ping the bank without deadlock.