Asp.Net Signal R - Detect Changes in Database ? Asp.net Web Forms

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 06:47:05

问题


So I have a List View inside an Update Panel

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

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)

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


回答1:


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

It basically uses SqlDependency to subscribe changes in Sql Server.

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);



回答2:


I dont think you can use SignalR to detect changes in the database, but to push the changes to the web-site. Use something like SqlDependency or SQL Notification Services to detect the changes in the database and then SignalR to push them to the web-page.



来源:https://stackoverflow.com/questions/15510610/asp-net-signal-r-detect-changes-in-database-asp-net-web-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!