Asp.Net Signal R - 检测数据库中的变化?Asp.net 网络表单 [英] Asp.Net Signal R - Detect Changes in Database ? Asp.net Web Forms

查看:31
本文介绍了Asp.Net Signal R - 检测数据库中的变化?Asp.net 网络表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在更新面板中有一个列表视图

So I have a List View inside an Update Panel

Update Panel
    List View
        Email 1
        Email 2
        Email 3
           ...

我正在尝试在 ASP.NET 中做一个类似于 GMAIL 的收件箱,我唯一苦苦挣扎的是如何检测数据库更改(即发送新消息时)并将该消息推送到 ListView 以模拟用户收到了一条新消息(就像 gmail 一样)

I'm trying to do an inbox similar to GMAIL in ASP.NET, the only I'm struggling with is how to detect DataBase Changes (ie when a new message is sent) and Push that message into the ListView to simulate that the user has received a new message (just like gmail does)

如何使用 SignalR 检测数据库更改并使用 SignalR 将它们推送到列表视图中?有可能吗?

How do I use SignalR to detect database changes and push them into the List View using SignalR? Is it possible?

推荐答案

如果您使用的是 Sql Server,请点击此链接.http://techbrij.com/database-change-notifications-asp-net-signalr-sql依赖

If you are using Sql Server follow this link. http://techbrij.com/database-change-notifications-asp-net-signalr-sqldependency

它基本上使用 SqlDependency 来订阅Sql Server 的变化.

It basically uses SqlDependency to subscribe changes in Sql Server.

如果您不使用 Sql Server,则必须手动执行此操作.对于视图方面,您可以使用 KnockoutJS 或 angular 来轻松修改列表.

If you aren't using Sql Server you have to do this manually. And for view side you can use KnockoutJS or anngular for easy list modification.

//Set up dependency
protected void Application_Start()
{
        //...
   SqlDependency.Start(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); 
}


protected void Application_End()
{
    SqlDependency.Stop(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); 
}


SqlDependency dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);

这篇关于Asp.Net Signal R - 检测数据库中的变化?Asp.net 网络表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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