简体   繁体   中英

keep a watch on sql server table field value using c#

I am developing ac# winform app to create a reminder of appointment time. I have a SQL table having varing appointment times of the customer and I want to popup a message if any time matches with current system time.

My app is running continuously. Right now I have tried using a timer which would fire a query on sql table every 1 minute to fetch time from sql and match current time. I am consurned with hours and minutes both.

But I am confused whether it is right or not to query a table every 1 minute. Even a if I make a windows service it will follow the same process.

Please suggest me a way out. Regards

Querying a table every minute is not, by any means, a heavy load. What are your main concerns?

If you are concerned about the database being offline for some reason, it may be better to load the appointments into some type of List<AlarmTimes> , and update them every minute if the database is available.

Net Framework has SqlDependency class. You can find examples of using it easily.

Also you can read this article about query notifications

I know of no way to have the database push you back data.

If your data table has a last modified field on it though, you could construct your query to only pull down data which has changed since the last time you communicated with the database. This will reduce the amount of data going over the wire. You can then keep a list of appointments for the next 8 hours to so. This has the added benefit of your app being able to provide best effort when the database is not reachable.

This will worst case mean you miss an appointment which was added or modified to be inside your update window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM