SQL Server Database Change Listener C#

前端 未结 5 716
灰色年华
灰色年华 2020-12-01 09:40

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 h

相关标签:
5条回答
  • 2020-12-01 09:57

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

    0 讨论(0)
  • 2020-12-01 10:05

    I've never used them before, but have you tried SQL Server Events notifications? See this article: Getting Started with SQL Server Event Notifications

    0 讨论(0)
  • 2020-12-01 10:10

    If you are using SQL Server 2008, there is a built in Change Data Capture that's pretty handy.

    http://msdn.microsoft.com/en-us/library/bb522489.aspx

    You can read the CDC data.

    0 讨论(0)
  • 2020-12-01 10:14

    I would use a table with a single row in the db to catalog last updated, inserted, or deleted events and then create triggers on each table of importance to update this table and then poll this table for changes.

    0 讨论(0)
  • 2020-12-01 10:18

    The DataContext won't offer you any type of listener functionality with SQL Server. Your best bet is to create a polling application, or even a separate thread which polls the database periodically for changes and expose an event which your main application can listen to.

    0 讨论(0)
提交回复
热议问题