异常信息: First chance exception at $7532C54F. Exception class EMSSQLNativeException with message '[FireDAC][Phys][ODBC][SQLSRV32.DLL] SQL_NO_DATA'. Process XXX.exe (6376) First chance exception at $7532C54F. Exception class EFDException with message '[FireDAC][DApt]-400. Update command updated [0] instead of [1] record. Possible reasons: update table does not have PK or row identifier, record has been changed/deleted by another user'. Process XXX.exe (6376)
根据信息检测,对应主键的数据没有被其他用户占用,没有被删除,客户端传过来的数据包有修改,即changcount>0。但是执行更新,却更新不了。
----------------------------------------------
Everyone will to do best!
Reviewing Errors If an error happens inside the ApplyUpdates call, then ApplyUpdates records the error into the internal data record structure and continues to process updates until the number of errors will be equal to or greater than AMaxErrors. ApplyUpdates does not raise exceptions. To process all erroneous records after the ApplyUpdates call, use either reconciling process, either filter erroneous records. To reconcile records, assign the OnReconcileError event handler and call the Reconcile method. The OnReconcileError event handler allows analyzing error, reading / changing the current record field values. On exit, it should assign action, which action the FireDAC code should take on the current record with the error. After the Reconcile method calls, ApplyUpdates may be called again to try to post erroneous record changes. To filter erroneous records, include rtHasErrors into FilterChanges. Then navigate through the dataset and read the RowError property to get an exception object associated with the current record. For example:
var oErr: EFDException; ... if FDQuery1.ApplyUpdates > 0 then begin FDQuery1.FilterChanges := [rtModified, rtInserted, rtDeleted, rtHasErrors]; try FDQuery1.First; while not FDQuery1.Eof do begin oErr := FDQuery1.RowError; if oErr <> nil then begin // process exception object ... end; FDQuery1.Next; end; finally FDQuery1.FilterChanges := [rtUnmodified, rtModified, rtInserted]; end; end;
是设置断点跟踪的时候,执行到FDQuery1.ApplyUpdates时,触发异常。 FDQuery1.ApplyUpdates返回值是1,如果返回值是0,则表示执行FDQuery1.ApplyUpdates成功!
----------------------------------------------
Everyone will to do best!
郁闷啊! 不知道是不是数据库的问题,重新建立一下主键,再来执行保存,则可以保存正常! 但是之前一建立主键之后就没有改过,也能正常更新一段时间,但是后面就出现这个更新不了的问题。
----------------------------------------------
Everyone will to do best!
还有,FireDAC对于MSSQL数据库的bit类型字段处理得不好,不能存在空值,或者干脆换成int类型。这样就不会出现以上的异常信息,就能正常保存数据了!
----------------------------------------------
Everyone will to do best!