Refresh database automatically


I would like to update (refresh) a MS-SQL table let's say every minute. So any new records or changes are presented to me.

Of course refreshing should only be executed when the table is in dsBrowse mode.
Refreshing has only to occur when a certain form is opened.
So user opens the form containing the grid of the MS-SQL table.

Can anybody give me an example on how to implement this? Please keep it as simple as possible.

Stef MerlijnDeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike LittlewoodEngineerCommented:
Surely the only way would be to close and reopen the query to the table to specifically call a refresh or am I wrong?
Hello Sir,

   To refresh the only way is to Close and Open the Query as mikelittlewood says. If this should happen when you open the form you could do it on FormActivate, but this will not be called when you move from one application to another application, but calls when you move from one form to another form, if you wish to do this refreshing when you move from one application to another application, then here is the code to do it.

procedure AppOnActivate(Sender: TObject);
//declare the above procedure definition in the private section of  Form1.

procedure TForm1.FormCreate(Sender: TObject);
    Application.OnActivate := AppOnActivate;

procedure TForm1.AppOnActivate(Sender: TObject);

with regards,
Stef MerlijnDeveloperAuthor Commented:
The problem isn't so much refreshing the table, but how to do it automatically.
Maybe a thread can be used or a timer, but I don't know how to implement it in such a way that it won't interfere with changes made by the enduser.
There is no other application that needs access to the database.
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Stef MerlijnDeveloperAuthor Commented:
By the way I use a TMySQLTable that has property Refresh.
Another approach is to use a timer that runs a stored procedure that returns some sort of checksum on the table, if that value has changed then refresh the data else don't bother,
Stef MerlijnDeveloperAuthor Commented:
pcsentinel: Could you give an example for that?
say your table has

ID > int AutoID
Name > clientname
Address > address
LastUpdate > int > field that is incremented everytime the record is edited

right a stored proc that

sums the ID+LastUpdate field for all records

sorry dont know MySQL so not sure of Syntax, but for SQL Server would be something like

@Checksum int OUTPUT
  SET @Checksum=(SELECT SUM(ID + LastUpdate) FROM MyTable)

when they first open the table run the query to get your staring checksum

then on a timer say every 5 secs, run the GetCheckSum procedure and if its different then you know you need to refresh the display, check that the user is in dsBrowse mode, if not then you dont need to worry because they will refresh the data after the edit.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Stef MerlijnDeveloperAuthor Commented:
That is very nice suggestion.
I've tested it and it works just fine.
Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.