SignalR和SqlDependency刷新问题-ASP.NET [英] SignalR and SqlDependency refreshment issue - ASP.NET

查看:52
本文介绍了SignalR和SqlDependency刷新问题-ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MSSQL数据库中有一个表,并且有一个ASPX页面,我需要将所有新行以降序推入该页面.我发现正在使用SignalR的这真棒教程和SqlDependency,它仅显示最后一行,舍弃了我在线时添加的前几行,这是因为它具有一个span元素来显示数据,并且每次覆盖此span时,所以我将JavaScript代码修改为附加新数据即可正常工作.

I have a table in MSSQL database, and I have an ASPX page, I need to push all new rows to the page in a descending order. I found this awesome tutorial which is using SignalR and SqlDependency and it shows only the last row descarding the previous rows which have been added when I'm online, it does that because it has a span element to show data and every time it overwrites this span, so I modified the JavaScript code to append the new data and it works fine.

现在的问题是,当我第一次刷新页面时,我将两次获得新行,如果再次刷新页面,我将使新行变成三倍..依此类推.

The problem now is when I refreshed the page for the first time, I'll get the new rows twice, and if I refreshed the page again I'll get the new rows triple .. and so on.

唯一的解决方案是关闭该应用程序,然后再次将其重新打开,就像重置IIS一样.

The only solution is to close the application and reopen it again, it looks like reset the IIS.

那么,如何避免在线节目中重复数据?

So, what can I do to avoid duplicating data in the online show?

推荐答案

虽然我绝对不喜欢这种方式,但我已经在Global.asax文件和我检查的Page_Load事件中声明了一个静态成员.它的值(如果为真),请不要运行新的SqlDependency实例,否则请运行它.

I got it, although I don't like this way absolutely, I have declared a static member in the Global.asax file and in the Page_Load event I checked its value, if it was true don't run a new instance of SqlDependency, otherwise run it.

if (!Global.PageIsFired)
            {
                Global.PageIsFired = true;
                SqlDependency.Stop(ConfigurationManager.ConnectionStrings["db"].ConnectionString);
                SqlDependency.Start(ConfigurationManager.ConnectionStrings["db"].ConnectionString);
                SendNotifications();
            }

亲爱的@Wasp,您的上一次更新对我了解了很多问题,非常感谢,感谢您的宝贵时间和及时的支持.

Dear @Wasp, Your last update helped me a lot to understand the problem, so thank you so much for your time and prompt support.

亲爱的@dyatchenko,非常感谢您的评论,它也非常有用.

Dear @dyatchenko, Thanks a lot for your comments, it was very useful too.

这篇关于SignalR和SqlDependency刷新问题-ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆