Database Update Not Reflected in Browser using SignarlR
<p>I'm new to SignalR. When I implement the following code, the database changes are not reflected in the browser at the same time.</p>

<p>Javascript code</p>

<pre><code>    $(function () {
        var notify = $.connection.notificationsHub;

        notify.client.displayNotification = function (msg) {
            console.log(msg);
            $("#newData").html(msg);
        };

        // Start the connection.
        $.connection.hub.start().done(function () {
            alert("connection started");
        }).fail(function (e) {
            alert(e);
        });

        //$.connection.hub.start();
    });
</code></pre>

<p>C# code
 NotificationsHub Class</p>

<pre><code>    public void NotifyAllClients(string msg)
    {
        IHubContext context = GlobalHost.ConnectionManager.GetHubContext&lt;NotificationsHub&gt;();
        context.Clients.All.displayNotification(msg);
    }

    public void SendNotifications()
    {
        string message = string.Empty;
        string conStr = ConfigurationManager.ConnectionStrings["MvcDemoDb"].ConnectionString;

        using (SqlConnection connection = new SqlConnection(conStr))
        {
            string query = "SELECT [Message] FROM [dbo].[Messages]";

            using (SqlCommand command = new SqlCommand(query, connection))
            {
                command.Notification = null;
                SqlDependency dependency = new SqlDependency(command);
                dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    reader.Read();
                    message = reader[0].ToString();
                }
            }
        }
        NotificationsHub nHub = new NotificationsHub();
        nHub.NotifyAllClients(message);
    }

    private void dependency_OnChange(object sender, SqlNotificationEventArgs e)
    {
        if (e.Type == SqlNotificationType.Change)
        {
            SendNotifications();
        }
    }
}
</code></pre>