Issue of Multiple SQL Notifications in ASP.NET Web Application on Page Refresh

How to refresh aspx page from sql server

Even though the server may be notified when data has changed, the real challenge is communicating those changes to the client in real-time without requiring a timer or user interaction.

You have a couple of options:

  1. Your best bet is to use a WebSocket, which enables bidirectional communication between the client and server. This is the solution I would pick.

    Here are some examples using WebSockets:

    • Building real-time web apps with WebSockets using IIS, ASP.NET and WCF
    • HTML5 C# WebSockets Server and ASP.NET Client Implementation
    • C# WebSocket Server
    • WebSockets in ASP.NET 4.5
    • WebHooks and WebSockets in ASP.NET



    There are a few good libraries around too that will take care of most of the leg work. A couple to check out are WebSync and PokeIn. Both products offer decent documentation and community editions that you can download for free.

    Here are some tutorials to check out:

    • WebSync Tutorials
    • PokeIn Basic Tutorial / PokeIn Advanced Tutorial


  2. Use AJAX to poll for changes every X number of seconds. If changes are detected reload the page, otherwise do nothing.

page refresh only when new records are inserted in database

For SQL 2005 and onwards you'd use SQL Server Query Notifications and the SqlDependency class in C#

There is a tutorial here that you can follow for SQL2005 onwards.

ASP.Net has SqlCacheDependency which is slightly different and works for earlier versions of SQL as well as current versions (it uses polling in SQL2000 and service broker in SQL2005+), but is ASP.Net specific, so you may have difficulty using it in a non web application.

SignalR notification never reload the page

The SignalR Hubs API enables you to make remote procedure calls (RPCs) from a server to connected clients and from clients to the server. In server code, you define methods that can be called by clients, and you call methods that run on the client.

In client code, you define methods that can be called from the server, and you call methods that run on the server. SignalR takes care of all of the client-to-server plumbing for you.client can call hub inherited method only.

Call BroadcastData methods that run on the server:

hubNotify.client.BroadcastData = function () {  
getAll();
};

Ref: Link



Related Topics



Leave a reply



Submit