每当数据库更新时更新 C# 客户端

发布于 2024-09-24 14:45:08 字数 331 浏览 0 评论 0原文

我正在将 MySQL 与 C# / Visual Studio 2008 一起使用。我需要知道任何方法,以便如果一个用户更新数据库,所有通过网络登录的用户都会收到通知,发生了更改。 如果我通过我的应用程序登录数据库,当时数据库中最新记录的序列号是10,然后我有权限的人更新了数据库中的记录,同时我收到通知数据库已更新为新记录。 常见的例子是当朋友上线时 MSN Messenger 的提醒... 虽然我真的不想要那个弹出窗口,但警报功能就是这样的......

还有一件事要问: 我想要一个功能,例如如果记录的状态未更新(例如超过 3 小时),那么我希望所有用户也能收到有关该问题的警报。所有记录都需要此功能,而不是专门针对新记录。

I am using MySQL with C# / Visual Studio 2008. I need to know any method so that if one user updates the database, all the logged in users over the network, are notified that a change has been occurred.
If i logged in the database through my application, at that time the serial no of the latest record in the database was 10, and then i someone with the privileges updates the record in the database and at the same time i am being notified that the database has been updated with a new record.
Common example can be of MSN messenger's alert for a friend when he gets online...
Though i really don't want that popup, but alert functionality is something like that...

One more thing to ask:
I want a functionality like if a record's status is not updated (for say about more than 3 hours), then i want all users to get alert about that issue also. This functionality is needed for all of the records, not specifically for new records.

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

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

发布评论

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

评论(3

本王不退位尔等都是臣 2024-10-01 14:45:08

答案很长,但最好的选择是 SqlCacheDependency

您还可以使用一种称为“反向 AJAX”的技术,该技术由 Google Mail 通知使用,并在此处讨论:Gmail 上的传入邮件通知如何工作?

除了这两个之外,您自己的其他选项 AFAIK 是简单的服务器轮询。

另外,您还没有提到您的客户是什么。

它是互联网上的公共网站吗?它是一个 Intranet 应用程序,还是一个 WPF 应用程序?

如果它是一个网站,那么最好是使用我提到的反向 AJAX 技术进行客户端回调。

Quite a long answer, but your best bet would be something like SqlCacheDependency.

Also you could use something called the "Reverse AJAX" technique, which is used by Google Mail notifications, and talked about here: How does incoming mail notification on Gmail works?

Besides those two, your own other options AFAIK is simple server polling.

Also, you haven't mentioned what your client is.

Is it a public web site on the internet? Is it an intranet app, it is a WPF app?

If it's a web site, you're best best is client-side callbacks using the Reverse AJAX technique i mentioned.

_失温 2024-10-01 14:45:08

您可能需要在客户端中设计某种投票功能。例如,您可以每分钟发送一个请求,询问数据库“自[客户端最新更新日期]以来您是否更新过任何内容?”如果数据库回答true,您可以让客户端请求完整的更新集。如果没有,你让它再睡一分钟。

You probably need to design some kind of poll functionality in your client. For example, you can send a request each minute asking the database "Have you updated anything since [date the client latest got updates]?" If the database answers true, you let the client request the full set of updates. If not, you let it sleep another minute.

ヅ她的身影、若隐若现 2024-10-01 14:45:08

使用 SqlDependency 类是使所有数据驱动更快、更高效的更好方法。它只是消除了每次数据发生更改时不断重新查询数据库检查的需要。

Using the SqlDependency Class is a better way to make all your data driven more faster and efficient. It just remove the need of constantly re-query your database checking every time when a changes is made in the data.

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