locked
ASP .net SignalR with SQLDependency - receiving multiple notifications instead of one for a single row update on SQL Server table RRS feed

  • Question

  • User-1319896600 posted

    Hi,

    I have set up signalR implementation using a table that has only one row using SQLDependency. The SQL database has been enabled with ENABLE_BROKER. Each time a change is made to this table (I update a column of this single row table), I receive a notification on my browser. This works as expected. I put an alert in the client side javascript in the function that receives the update notification. I am observing that the alert goes off multiple times for one change on the SQL Server database table.

    var notifications = $.connection.signalRHub;

    notifications.client.updateTable = function () {

                       alert("update notification through asp .net SignalR!!!");   ***This alert goes off multiple times (anywhere from 3 to sometimes even more than 10) when I update a column of this single row table

    I expect this alert to go off just once. 

    Is there something that I am missing?

    Thanks

    Monday, July 6, 2015 10:45 AM

Answers

All replies

  • User-1319896600 posted

    This behavior goes away if I close and open Visual Studio. But if I run the app multiple times, the notifications seem to build up. It is weird though as I have a put a SQLDependency.Stop(connectionstring) in the Application_End method of Global.asax. 

    Monday, July 6, 2015 4:58 PM
  • User61956409 posted

    Hi ihaveaquestion,

    I am observing that the alert goes off multiple times for one change on the SQL Server database table.

    I recommend to debug your code to check if SqlDependency OnChange method is executed just once when you update the table.

    Best Regards,

    Fei Han

    Tuesday, July 7, 2015 12:47 AM
  • User-1319896600 posted

    If I close and start Visual Studio, then it the OnChange method is fired once for each update to the table.

    If I have Visual Studio open (without restarting) and have the application run multiple times locally, meaning, I run the application, make some updates and then stop the application by closing the browser, if I do this multiple times, then OnChange fires multiple times for each update to the table.

    Tuesday, July 7, 2015 12:00 PM
  • User71929859 posted

    Implement it as Singleton as shown in below tutorial

    http://www.asp.net/signalr/overview/getting-started/tutorial-server-broadcast-with-signalr

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 8, 2015 6:55 AM