Hi guys,
I have this situations :
- Use IBX for database operations
- Use TIBDataset with CacheUpdate Enabled
I have an TDBEdit, with value = 'abc', then edit its value to 'abcde'
To Update database, I clicked Save button, which codes something like this
procedure TForm1.btnSaveClick(Sender: TObject);
var
Tbl : array [1..1] of TDataSet;
begin
Tbl[1] := Dt;
Dba.ApplyUpdates( Tbl);
ShowMessage('saved');
end;
That code works OK when network connection is OK, database value updated to 'abcde', but when network connection is lost, Dialog box showed with error message and option to click OK or Abort.
Error reading data from connection
That error was expected, if users click Abort, app closed, if user click OK, app not closed, value of TDBEdit in the screen still 'abcde'.
Problem is, when network connection restored again while app still open/ not restarted again, clicked again button Save still got same error like above.
Is IBX able to save data to the data when network connection is restore again without need to restart the app?
IBX depends on the Firebird Client library as does any Firebird database client. This does not have any explicit code to recover from lost connections. When a connection is lost, the Firebird server will put the current transaction into limbo which, in theory, could allow a database adminstrator to recover any "lost" data. However, that is not always an easy procedure.
In the case of an unstable connection, your strategies are:
1. In your client systems firebird.conf file set DummyPacketInterval=0. This will avoid timeouts on inactive connections when the underlying network is unstable. However, this will not help drop outs during an update. Could be problematic.
2. Don't use ApplyUpdates or cached updates in general. All this does it make it more likely that you will lose all your updates when a connection fails. Instead, set each dataset's AutoCommit property to acCommitRetaining. This will ensure that every update is written through to the database i.e. minimising the risk of data loss.
3. Add an event handler to your TIBDatabase component to automatically re-open the database after an unexpected disconnection. You will probably want to use Application.QueueAsyncCall in the event handler to queue the re-open to ensure a tidy-up before re-opening. Your re-open procedure should re-open all previously open datasets. They should then open in the state they were in after the last autocommit.