2

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?

Jack Pettinger
  • 2,715
  • 1
  • 23
  • 37
Eric Bergman
  • 1,453
  • 11
  • 46
  • 84

2 Answers2

4

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);
adt
  • 4,320
  • 5
  • 35
  • 54
2

I don't 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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Eystein Bye
  • 5,016
  • 2
  • 20
  • 18