本文介绍了是否可以使用SQL表依赖性监视多个表数据更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi All

i want a solution that tell me how to monitor multi-table data change in c# console application.

i used SqltableDependency for one table and work Fine , but i want monitor multi tables

How to Monitor multiple Tables data change in sql server From console application ???





我尝试过:





What I have tried:

using (var tabledependency = new SqlTableDependency<Products>(connectionString, "Products"))
            {
                tabledependency.OnChanged += tableDependencyChanged;
                tabledependency.OnError += tableDependencyOnError;
                tabledependency.Start();
                Console.WriteLine("Waiting to Receive Notifications");
                Console.WriteLine("Press a key to stop");
                Console.ReadKey();
                tabledependency.Stop();
            }

推荐答案

引用:

SqlDependency允许您在数据库中的原始数据发生变化时接收通知,以便刷新缓存。



要设置依赖项,需要将SqlDependency对象与一个或多个SqlCommand对象相关联。要接收通知,您需要订阅OnChange事件。有关创建通知查询的要求的详细信息,请参阅SQL Server联机丛书中的为通知创建查询。

SqlDependency allows you to receive notifications when the original data in the database changes so that the cache can be refreshed.

To set up a dependency, you need to associate a SqlDependency object to one or more SqlCommand objects. To receive notifications, you need to subscribe to the OnChange event. For more information about the requirements for creating queries for notifications, see "Creating a Query for Notification" in SQL Server Books Online.







详情请见:

[]

[]

CodeProject知识库文章:

[]

[]




For further details, please see:
SqlDependency Class (System.Data.SqlClient)[^]
Detecting Changes with SqlDependency[^]
Articles of CodeProject Knowledge Base:
Query Notification using SqlDependency and SqlCacheDependency[^]
Using SqlDependency for data change events[^]


这篇关于是否可以使用SQL表依赖性监视多个表数据更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 06:37