更新数据库时通知我的WCF服务 [英] Notify my WCF service when my database is updated
问题描述
我有一个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.
感谢所有帮助!
rinze
All help is appreciated! rinze
推荐答案
如果您的数据库是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.
请注意,请勿从触发器调用外部进程,请勿从触发器进行Web调用。是保证灾难的良方。
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查询通知我建议将SQLDependency对象与LINQ一起使用。
For those interested in mixing Query Notifications with LINQ to SQL I recommend Using SQLDependency objects with LINQ.
这篇关于更新数据库时通知我的WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!