Search code examples
sql-serverdelphifiredac

NO_SQL_DATA error when deleting a record, firedac, delphi 10.3.1


using sql server and delphi 10.3.1, and firedac.

I am using cached updates, with autocommit on.

I keep managing to get my data into a state where the record has been deleted from the database, and I have also deleted that record in the dataset.

then, when it attempts to commit the change to the database(where the data no longer exists), I get an error: [my application] raised exception class emssqlNativeException with message [firedac][Phys][odbc][sqlncli11.dll] SQL_NO_DATA and then I can't clear the cached updates flag on the dataset, because there is stuff 'sitting' there.

my question - how can I get it to NOT return that error? because it's really not an error, it's trying to delete a record that no longer exists. I am not finding ANY documentation on the update options on a query, so is there a flag there I need to set?


Solution

  • You can handle update errors in OnUpdateError and perform any additional checks before deciding how to proceed. Blindly pretending all deletes worked would be something like:

    procedure TForm1.FDQuery1UpdateError(ASender: TDataSet; AException:
        EFDException; ARow: TFDDatSRow; ARequest: TFDUpdateRequest; var AAction:
        TFDErrorAction);
    begin
       if ARequest = ARDelete then AAction := eaApplied;
    end;
    

    Read the online help for OnUpdateError for more information.