Hello,
It is the correct behaviour. When you start editing the first dataset, MyDAC starts a transaction on a server (that works for a session, i.e. TMyConnection). When you post a new inserted record in the second dataset, it is done in the transaction context of a session. Because LockMode is used only for edited records (because several users can change them simultaneously), the transaction is not committed at the post operation of the second dataset. When you post changes made in the first dataset, MyDAC determines that there were no changes and rollbacks the transaction.
To avoid this problem, you should use two connections for inserting and editing records. Here is a code example:
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
begin
Query1.Connection := MyConnection1;
Query2.Connection := MyConnection2;
Query1.LockMode := lmPessimistic;
Query2.LockMode := lmPessimistic;
Query1.Open;
Query2.Open;
Query1.Edit;
Query2.Insert;
Query2.FieldByName('Field1').AsString := 'Value1';
Query2.Post;
Query1.Post;
end;