Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi Folks,

in my asp.net website I have signalR installed and when an exception is recorded in the Errors Table of my MS SQL Server the SqlDependency is run, the error is received from the db, the ErrorHub sends the message to all context.Clients.all....
My page shows a pnael with the message for 5 seconds. So far so good.
I then click on a menu choice. Change from default to another aspx page (with the same master page). If an error is set in the db, the SqlDependency works, the ErrorHub sends to context.Clients.All, but the panel is not shown anymore. How come?

What I have tried:

C#
[HubName("errorHub")]
    public sealed class ErrorMessages : Hub
    {
        private Dependencies.DependencyGenericHandler _dependency;
        private DateTime _currentTime;

        private ErrorMessages()
        {
            _currentTime = DateTime.Now;
            _dependency = new Dependencies.DependencyGenericHandler("MVS.SQLDEP_Errors");
            _dependency.ClearParameters();
            _dependency.AddParameters("@ModifiedByUser", Accounts.AccountControl.CurrentUsername);
            _dependency.AddParameters("@CurrentDateTime", _currentTime);
            _dependency.DependencyResult += Dependency_DependencyResult;
        }

        public static readonly ErrorMessages Instance = new ErrorMessages();

        public void CallDepency()
        {
            try
            {
                _dependency.DependencyResultTable();
            }
            catch (Exception err)
            {
                Logging.Log.AddException(err);
            }
        }

        [HubMethodName("displayErrorMessage")]
        public void Dependency_DependencyResult(DataTable resultTable)
        {
            try
            {
                _dependency.DependencyResult -= Dependency_DependencyResult;
                StringBuilder sb = new StringBuilder();
                Parallel.ForEach(resultTable.AsEnumerable(), row =>
                {
                    sb.AppendLine($"{row.Field<string>("Errormessage")}{Environment.NewLine}");
                });
                var context = GlobalHost.ConnectionManager.GetHubContext<ErrorMessages>();
                context.Clients.All.displayErrorMessage(sb.ToString());
                _dependency.DependencyResult += Dependency_DependencyResult;
            }
            catch (Exception err)
            {
                Logging.Log.AddException(err);
            }
        }
    }


My jQuery =
JavaScript
<script type="text/javascript">
            $(function () {
                var errorHub = $.connection.errorHub;

                errorHub.client.displayErrorMessage = function (resultTable) {
                    try {
                        $('#<%=PnlErrors.ClientID %>').show();
                        $('#<%= LbLError.ClientID %>').text(resultTable);
                        setTimeout(" $('#<%=PnlErrors.ClientID %>').hide();", 5000);
                        
                    }
                    catch (e) {
                        console.log(e);
                    }
                }
            });

            $.connection.hub.start()
                .done(function () { console.log('Now connected, connection ID=' + $.connection.hub.id); })
                .fail(function () { console.log('Could not Connect!'); });

           
        </script>
Posted
Updated 7-May-18 23:55pm

1 solution

Issue is solved. It was a caching thing in the browser...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900