SQL Server数据库更改监听器C# [英] SQL Server Database Change Listener C#

查看:641
本文介绍了SQL Server数据库更改监听器C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要听为从C#SQL Server数据库中的数据进行更改。我希望会有一些听众,我可以用它来确定,如果我有数据是陈旧的。尽管是一个相当常见的场景我找不到这是不是简单地查询数据库中的任何解决方案。

I want to listen for changes to data in a SQL Server database from C#. I was hoping that there would be some sort of listener which I could use to determine if data that I have is stale. Despite being a fairly common scenario I can't find any solutions which aren't to simply poll the database.

我使用的 LINQ到SQL 的访问数据,因此具有的的DataContext 的对象,我希望我能听的数据更改事件,但我可以'T似乎发现之一。

I use Linq-To-SQL to access the data and hence have a DataContext object, I was hoping I could listen for an on data changed event but I can't seem to find one.

我AP preciate,这是一个不平凡的屏障(从C#方法到SQL Server DB),我希望这是一个解决的问题的原因是,它是图形用户界面的共同要求。如果这是不可能听更新怎么给你保持数据显示在一个新的GUI(当它由一个SQL Server数据源的支持)。

I appreciate that it's a non-trivial barrier (From C# method to SQL Server DB), the reason I expected this to be a solved problem is that it's a common requirement for GUIs. If it's not possible to Listen for updates how to you keep the Data displayed in a GUI fresh (When it's backed by a SQL Server data source).

虽然这不是GUI的工作,我期待,以适应来自该领域的东西。

Although this isn't for GUI work I was expecting to adapt something from that realm.

有没有办法来订阅SQL Server数据库变化事件在C#?

推荐答案

您正在寻找的<一个href=\"http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency.aspx\"><$c$c>SqlDependency类,它允许你听更改到一个SQL查询的结果集。

You're looking for the SqlDependency class, which allows you to listen for changes to the resultset of a SQL query.

这篇关于SQL Server数据库更改监听器C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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