简体   繁体   English

使用C#监视SQL Server表字段值

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

I am developing ac# winform app to create a reminder of appointment time. 我正在开发ac#winform应用程序,以提醒约会时间。 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. 我有一个SQL表,其中包含客户的不同约会时间,如果任何时间与当前系统时间匹配,我想弹出一条消息。

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. 现在,我尝试使用一个计时器,该计时器每1分钟在sql表上触发一次查询,以从sql中获取时间并匹配当前时间。 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. 但是我困惑每隔1分钟查询一个表是否正确。 Even a if I make a windows service it will follow the same process. 即使我进行Windows服务,它也会遵循相同的过程。

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. 如果您担心数据库由于某种原因而脱机,最好将约会加载到某种类型的List<AlarmTimes> ,并在数据库可用时每分钟更新一次。

Net Framework has SqlDependency class. Net Framework具有SqlDependency类。 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. 然后,您可以保留接下来8个小时的约会列表。 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. 这将是最坏的情况,意味着您错过了在更新窗口中添加或修改的约会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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