Detecting when change notification message processing is complete

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
bryn.ball
Posts: 9
Joined: Mon 08 Dec 2014 03:32

Detecting when change notification message processing is complete

Post by bryn.ball » Wed 21 Nov 2018 21:07

I am a newbie to change notification processing and am rather overwhelmed by the amount of information that Microsoft provide on this topic.

My question is ...

Is there any way to tell whether all change notification messages relevant to the current instance of an application have been addressed by the application before proceeding to the next process statement?

I am currently using a Sleep command to ensure messages are cleared after issuing a Commit statement but this seems too arbitrary for my liking. I am doing this because if I don't do this I receive "record has been changed by another user" exceptions which interrupt the processing I am attempting to execute.

Any guidance or re-orientation on my approach that you can provide would be appreciated.

Stellar
Devart Team
Posts: 248
Joined: Tue 03 Oct 2017 11:00

Re: Detecting when change notification message processing is complete

Post by Stellar » Fri 23 Nov 2018 15:45

Please specify which of the cases interests you?
1. When changing the data in your application, you want to automatically notify all other applications that the data has been changed and to be sure that all other applications will respond to received messages.
2. You want, before performing any operation, to check whether all messages were received and processed by your application.

bryn.ball
Posts: 9
Joined: Mon 08 Dec 2014 03:32

Re: Detecting when change notification message processing is complete

Post by bryn.ball » Thu 21 Feb 2019 19:57

Hi Stellar
It is the second option, "to check whether all messages were received and processed by your application..."
Thanks
Bryn

Stellar
Devart Team
Posts: 248
Joined: Tue 03 Oct 2017 11:00

Re: Detecting when change notification message processing is complete

Post by Stellar » Mon 25 Feb 2019 14:20

After the Commit method has been executed, all messages from the server have already been processed by SDAC, and nothing should interfere with the execution of the next SQL expression. The "record has been changed by another user" issue may occur if, from the point the data was received until the point of editing, the record was changed on the server. You can try updating the field values before editing the record by calling the RefreshRecord method. For example:

Code: Select all

MSQuery1.SQL.Text := 'SELECT DeptNo, DName FROM Dept';
MSQuery1.Open;

// Some kind of data processing ...
// During this time, data on the server can already be changed

MSQuery1.RefreshRecord;
MSQuery1.Edit;
MSQuery1.FieldByName('DName').AsString := 'New value';
MSQuery1.Post;

Post Reply