数据库更新托盘通知

发布于 2024-09-12 14:45:50 字数 112 浏览 3 评论 0原文

我想构建一个小应用程序,每当更新或插入 SQL Server 数据库中的某个表时,它都会弹出托盘通知(或 Toast 弹出窗口或其他内容)。

如果可能的话,我想避免轮询,那么最简单的方法是什么?

i want to build a little app that pops up a tray notification (or a toast popup or something) whenever an update or insert going into a certain table in a SQL server database.

What is the simplest way of doing this as i want to avoid polling if possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

丢了幸福的猪 2024-09-19 14:45:51

查询通知。这是 SQL Server 的功能,允许应用程序在数据更改时订阅从服务器推送的通知。它通常通过 SqlDependency 类来利用。

我最近发布了 LinqToCache 项目允许您向 LINQ 查询添加基于 SqlDependency 的通知和缓存失效:

var query = (from r in ctx.table select r).AsCached(
 "table", new CachedQueryOptions() {
    OnInvalidated = (sender, args) {
      // the query was invalidated, data has changed
      // refresh display or notify user
    }
 });

Query Notifications. This is the SQL Server feature that allows an application to subscribe to notifications pushed from the server when data is changed. It is usually leveraged through the SqlDependency class.

I have recently posted the LinqToCache project that allows you to add SqlDependency based notifications and cache invalidation to LINQ queries:

var query = (from r in ctx.table select r).AsCached(
 "table", new CachedQueryOptions() {
    OnInvalidated = (sender, args) {
      // the query was invalidated, data has changed
      // refresh display or notify user
    }
 });
嘴硬脾气大 2024-09-19 14:45:51

扩展存储过程也是我首先想到的,如果我想在 SQL Server 本身上运行监控应用程序,这可能是我会使用的解决方案。但我猜情况可能并非如此。

我本人建议使用 MSMQ 作为中间层,因为现在几乎每个版本的 Windows 都附带它,并且或多或少是为此类事情量身定制的。因此,浏览各层,在这里,您有:

  1. 特定表上的 UPDATE 和 INSERT 触发器,它们调用...
  2. ....NET 程序集(使用 CLR 集成添加),其中...
  3. ...放置一条消息描述对服务器上的 MSMQ 队列的插入/更新,它...
  4. ...由您的托盘应用程序接收,无论它在哪里运行...
  5. ...然后显示。

这里有从 SQL Server 访问 MSMQ 的示例代码: http://www.codeproject.com /KB/database/SqlMSMQ.aspx

Extended stored procedures are what I thought of first, too, and are probably the solution I'd use if I wanted to run the monitoring app on the SQL Server itself. But I'm guessing that's probably not the case.

I'd suggest using MSMQ as an intermediate layer, myself, since it comes with just about every version of Windows these days and is more or less tailor-made for this sort of thing. So, going through the layers, here, you have:

  1. UPDATE and INSERT triggers on your certain table, which call...
  2. ...a .NET assembly (added using CLR integration), which...
  3. ...puts a message describing the insert/update into an MSMQ queue on the server, which...
  4. ...is received by your tray app, wherever it's running...
  5. ...and then displayed.

There's sample code for accessing MSMQ from SQL Server here: http://www.codeproject.com/KB/database/SqlMSMQ.aspx

鸩远一方 2024-09-19 14:45:51

您可以触发扩展存储过程 ,这会通知您的托盘。

也许这个链接更好。

You could trigger extended stored procedure, which would notify your tray.

Maybe this link is better.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文