当我的数据库更新时通知我的 WCF 服务 [英] Notify my WCF service when my database is updated

查看:21
本文介绍了当我的数据库更新时通知我的 WCF 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WCF 服务,需要在数据库发生更改时通知它的客户端 (sql server 2005).这相对容易完成,只要我找到一种方法将任何更改通知我的服务.我可能可以在表上创建一个数据库触发器,并让该触发器启动一个通知我的服务的小型服务客户端,但我想知道是否有更好的方法来做到这一点?让服务轮询数据库以获取更改将是一个可行的解决方案,但我不确定这样做的最佳方法(并且最好向我的服务发送通知).

I have a WCF service that needs to notify it's clients when changes occur to the database (sql server 2005). This is relatively easy accomplished, as long as I find a way to notify my service of any changes. I can probably create a database trigger on a table and have that trigger start a small service client that notifies my service, but I'm wondering if there's a better way to do this? It would be a viable solution to have the service poll the database for changes, but I'm not sure on the best way to do it (and sendign a notification to my service would be preferred).

由于相关更新仅适用于数据库的某个部分,我还想知道是否也可以将这种触发器(或其他机制)链接到数据库图表.

As the relevant updates apply only to a certain part of the database, I was also wondering if it's also possible to link such a trigger (or other mechanism) to a database diagram.

感谢所有帮助!凛

推荐答案

如果您的数据库是 SQL Server 2005 及以上版本,您可以尝试以下解决方案:从 WCF 前端移除数据更改池.

If your database is SQL Server 2005 and above you can try this solution: Remove pooling for data changes from a WCF front end.

作为旁注,永远不要从触发器调用外部进程,不要从触发器进行网络调用.是灾难的保证.

As a side note, never call external processes from a trigger, don't make web calls from a trigger. Is a guaranteed recipe for disaster.

更新

对于那些有兴趣将查询通知与 LINQ to SQL 混合使用的人,我推荐在 LINQ 中使用 SQLDependency 对象.

For those interested in mixing Query Notifications with LINQ to SQL I recommend Using SQLDependency objects with LINQ.

这篇关于当我的数据库更新时通知我的 WCF 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆