Hi all,
Still getting to grips with FireDAC. My current issue is how quick it is to give up when executing a TFDCommand and raise an exception about the table being locked.
The app in question has a thread that will update a record in a table (MSAccess). It uses a copy of the TFDConnection object to avoid multi-threading issues.
Meanwhile, the main thread has a TFDQuery open on the same table. I've set LockMode := lmPessimistic, and LockWait := True in the TFDConnection object, but I get frequent exceptions from the TFDCommand when it tries to execute. A solution I've tried that seems to mitigate the issue is to wrap the Execute in a loop ie.
This seems crazy. Surely I'm overlooking something. Isn't locking in FireDAC supposed to work as critical sections would amongst threads? If locking doesn't work properly, I'll have to manually handle it with critical sections.
Or - is the problem with MS Access, and should I porting to something like SQL Server?
Still getting to grips with FireDAC. My current issue is how quick it is to give up when executing a TFDCommand and raise an exception about the table being locked.
The app in question has a thread that will update a record in a table (MSAccess). It uses a copy of the TFDConnection object to avoid multi-threading issues.
Meanwhile, the main thread has a TFDQuery open on the same table. I've set LockMode := lmPessimistic, and LockWait := True in the TFDConnection object, but I get frequent exceptions from the TFDCommand when it tries to execute. A solution I've tried that seems to mitigate the issue is to wrap the Execute in a loop ie.
Code:
procedure TFDCommandEx.SafeExecute(ARetries: Integer);
var
c : Integer;
begin
for c := 1 to ARetries do
try
Execute;
Break;
except
on E: Exception do
begin
Logger.LogErr('TFDCommandEx', E);
if c >= ARetries then
raise
end;
end;
end;
This seems crazy. Surely I'm overlooking something. Isn't locking in FireDAC supposed to work as critical sections would amongst threads? If locking doesn't work properly, I'll have to manually handle it with critical sections.
Or - is the problem with MS Access, and should I porting to something like SQL Server?