C#/SQL 侦听器告诉我是否已将行插入到表中 [英] C# / SQL Listener to tell me if a row has been inserted into a table

查看:31
本文介绍了C#/SQL 侦听器告诉我是否已将行插入到表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以发布示例代码或告诉我如何设置侦听器以在新行插入 SQL Server 数据库时通知我(触发事件)吗?

Can someone post sample code or tell me how to set up a listener to notify me (trigger an event) if a new row is inserted into a SQL Server database?

我不想使用任何 SQL Server 消息传递或代理服务.我目前有一个文件侦听器,它会在新行附加到平面文件时通知我.我想对数据库表做同样的事情.

I don't want to use any of the SQL Server messaging or broker services. I currently have a file listener which will notify me when new rows are appended to a flat file. I would like to do the same for a database table.

推荐答案

您是否正在寻找 SqlDependency 类,让您的代码注册以在发生更改时收到通知?

Are you perhaps looking for the SqlDependency class, that lets your code register to be notified when changes occur?

SqlDependency 是缓存方案的理想选择,您的 ASP.NET 应用程序或中间层服务需要将某些信息缓存在内存中.SqlDependency 允许您在数据库中的原始数据发生变化时收到通知,以便刷新缓存.

SqlDependency is ideal for caching scenarios, where your ASP.NET application or middle-tier service needs to keep certain information cached in memory. SqlDependency allows you to receive notifications when the original data in the database changes so that the cache can be refreshed.

或者这是否属于你不允许的范围,这不是很清楚?

Or does this fall within the realm of things that you're disallowing, it's not entirely clear?

这篇关于C#/SQL 侦听器告诉我是否已将行插入到表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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