Hello,
I am using cached updates with TMSQuery and TMSConnection. I am seeing strange errors. For details, see http://crlab.com/forums/viewtopic.php?t=1428
Instead of trying to figure out what is wrong, perhaps I can tackle this from another angle... can you guys at CORELAB please provide a recommended sequence of commands to commit cached updates?
I am currently doing this:
if msQuery.State in dsEditModes then begin
msConnection.StartTransaction;
try
msQuery.ApplyUpdates;
msConnection.Commit;
except
msConnection.RollBack;
end;
end;
Another question: I have noticed that sometimes (rarely) following the Commit, the msQuery.State is still equal to dsEdit! How can that happen? Should that happen?
Thanks,
Doug
Recommended approach for using TMSQuery and TMSConnection
We recomend the following sequence. You can find it in "TMemDataSet.ApplyUpdates" topic of SDAC help
We cannot reproduce your problem with msQuery.State.
msQuery.ApplyUpdates always performs msQuery.Post operation.
Code: Select all
procedure ApplyButtonClick(Sender: TObject);
begin
with MyQuery do
begin
Session.StartTransaction;
try
... {Modify data}
ApplyUpdates; {try to write the updates to the database}
Session.Commit; {on success, commit the changes}
except
RestoreUpdates; {restore update result for applied records}
Session.Rollback; {on failure, undo the changes}
raise; {raise the exception to prevent a call to CommitUpdates!}
end;
CommitUpdates; {on success, clear the cache}
end;
end;
msQuery.ApplyUpdates always performs msQuery.Post operation.
Hi, thanks, I have made many changes to this sequence, and it all seems to be working now. One question though, your example shows CommitUpdates after the try block. Shouln't it be in the try block after DB.Commit? Like this:
procedure ApplyButtonClick(Sender: TObject);
begin
with MyQuery do
begin
Session.StartTransaction;
try
... {Modify data}
ApplyUpdates; {try to write the updates to the database}
Session.Commit; {on success, commit the changes}
CommitUpdates; {on success, clear the cache}
except
RestoreUpdates; {restore update result for applied records}
Session.Rollback; {on failure, undo the changes}
raise; {raise the exception to prevent a call to CommitUpdates!}
end;
end;
end;
procedure ApplyButtonClick(Sender: TObject);
begin
with MyQuery do
begin
Session.StartTransaction;
try
... {Modify data}
ApplyUpdates; {try to write the updates to the database}
Session.Commit; {on success, commit the changes}
CommitUpdates; {on success, clear the cache}
except
RestoreUpdates; {restore update result for applied records}
Session.Rollback; {on failure, undo the changes}
raise; {raise the exception to prevent a call to CommitUpdates!}
end;
end;
end;