每当通过 Web 应用程序将记录插入 SQL Server 时,就会触发 winforms 程序运行

发布于 2024-10-15 09:48:07 字数 244 浏览 2 评论 0原文

每当从 Web 应用程序在 SQL Server 数据库中添加一行时,我需要触发一个在任务栏托盘中运行的 Winforms 程序。有办法做到这一点吗?

目前,该程序一直运行,检查数据库中是否有新记录,如果没有插入任何内容,则休眠底层线程,但我还需要能够在用户从 Web 应用程序前端插入一行时触发该程序运行-结尾。

添加:Web应用程序、数据库和winforms在同一台服务器上运行。

谢谢

I need to trigger a Winforms program that runs in taskbar tray whenever a row is added in SQL Server database from a web app. Is there a way to do this?

At the moment, the program runs all the time checking the database for new record and sleeps the underlying thread if nothing is inserted, but I need also to be able to trigger the program to run whenever a user inserted a row from a web app front-end.

added: web app, database, and winforms are running on the same one server.

thanks

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

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

发布评论

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

评论(3

别靠近我心 2024-10-22 09:48:07

从 SQL Server 中的插入触发附加操作的“标准”方法:

如果附加操作是数据库本地的,并且完全可以在 Transact SQL 中实现,则建议将其编写为 触发器

如果附加操作无法在事务 SQL 中实现,那么您可能会考虑编写 CLR 触发器。然而,我再次强调,只有当发生的事情发生在数据库本地时,这才是合适的。

如果附加操作适合服务器,但依赖于其他数据库或服务器外部的其他功能,那么您通常希望将附加操作与原始 INSERT 操作分离。正如其他人所说,处理此问题的两种方法是 SqlDependency 或 Service Broker。

如果您要走 SqlDependency 路线,则需要永久运行的东西才能使用此对象。这是您通常放入 Windows 服务中的内容。

"Standard" ways of triggering additional actions from inserts in SQL Server:

If the additional action is local to the database, and entirely implementable in transact SQL, the recommendation would be just to write it in a trigger.

If the additional action isn't implementable in transact SQL, then you might consider writing a CLR trigger. However, again I'd say that this is only appropriate if whatever is going to happen is local to the database.

If the additional action is appropriate to the server, but relies on e.g. other databases, or other features outside of the server, then you'd generally want to decouple the additional actions from the original INSERT operation. Two ways of dealing with this are SqlDependency, as others have said, or Service Broker.

If you're going the route of SqlDependency, you need something running permanently to use this object. This is what you'd typically put inside a windows service.

铜锣湾横着走 2024-10-22 09:48:07

如果您可以稍微重构您的应用程序,则可能会创建一个双工 wcf 服务协定。这是关于该教程 http://msdn.microsoft.com/en-us /library/ms731184.aspx
这是 WCF 中可用的消息模式之一。您可以使用它来执行诸如从服务器触发事件​​之类的操作,客户端可以订阅这些事件,我认为这可能可以使用。

If you can refactor your application a bit, you could potentially create a duplex wcf service contract. here is a tutorial on that http://msdn.microsoft.com/en-us/library/ms731184.aspx
This is one of the message patterns available in WCF. You can use it to for doing things like firing events from the server, which the clients can subscribe to, which i think might be able to use.

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