从 SQL Server 数据库进行 AJAX 更新:返回的值不正确
我有一个 ASP.NET 报告界面,它显示从 SQL Server 后端返回的多个值。登录后,浏览器页面永远不会重新加载,但多个屏幕区域会通过 AJAX 调用在计时器上更新。
我的问题是屏幕区域间歇性地显示来自先前 AJAX 调用的值。我已经彻底深入地调查了这个问题好几天了,但我无法具体查明是什么原因造成的,或者如何完全克服它。目前,错误值非常罕见(例如,五万分之三),但我应该不会得到任何结果!以下是有关设置的一些详细信息:
- 屏幕刷新计时器每 30 秒运行一次以更新所有屏幕区域
- 屏幕区域更新之间有 1.5 秒的延迟
- 用于决定运行哪个 SQL 存储过程以从每个屏幕区域的数据库都正确地传递到 ASP.NET 接口 - 我知道 100% 确定运行存储过程的存储
- 过程将其值返回到 SQLDataReader,
- 读取器有时会产生似乎是从以前的 AJAX 交互中“缓冲”,即我正在使用正确的变量运行正确的存储过程,但是返回的值不是我在 SQL 查询界面中运行完全相同的命令时得到的值 - 它们是先前调用的结果
- 并在通过 IDisposable 接口使用后正确处置
- ,
- SQL 连接、命令和读取器都是针对每次交互重新创建和实例化的 ,因此它们应该在下一个运行之前完成,但屏幕区域更新之间有 1.5 秒的延迟,周期之间有 30 秒的延迟,因此它们在任何情况下都不应该相互冲突。
令人沮丧的是,读者在运行 SQL 语句时没有抛出异常,但似乎返回了先前交互的结果 - 而且这种情况很少见,但一个不正确的结果就太多了。
我根本没有使用 ASP.NET 状态管理 - 在 web.config 中关闭。
我缺少什么?
I have an ASP.NET reporting interface that displays several values that are returned from a SQL Server backend. Once logged in, the browser page is never reloaded, but several screen areas are updated on a timer through AJAX calls.
My problem is that the screen areas are intermittently displaying values that are coming from previous AJAX calls. I have thoroughly and intensively investigated the problem for a number of days and I haven't been able to specifically pinpoint what is causing it, or how to completely overcome it. Currently the incorrect values are very infrequent (3 in 50,000, say), but I should be getting none whatsoever! These are some details about the setup:
- the screen refresh timer runs every 30 seconds to update all screen areas
- there is a 1.5 second lag between the screen area updates
- the values used to decide which SQL stored proc to run to get the correct values from the database for each screen area are being passed in to the ASP.NET interface correctly - I know with 100% certainty which stored proc to run
- the stored proc returns its values to a SQLDataReader
- it is the reader that is sometimes yielding values that seem to be "buffered" from previous AJAX interactions, i.e. I am running the correct stored proc with the correct variables, but the values returned are not what I get if I ran that precise same command in a SQL query interface - they are results from a previous call
- the SQL connection, command and reader are all created and instantiated afresh for each interaction and disposed of correctly after use through the IDisposable interface
- I have swapped the reader for a dataset, with no difference in results
- my AJAX calls are synchronous (async=false), so they should each complete before the next one is run, but I also have the 1.5 sec delay between screen area updates and 30 secs between cycles, so they shouldn't run into each other in any event.
What is frustrating is that the reader is running a SQL statement without throwing an exception, but seemingly returning results from a previous interaction - and then only very seldom, but one incorrect result is one too many.
I am not using ASP.NET state management at all - switched off in web.config.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 sql server profile 分析到达 sql server 的 sql 语句。您可以通过这种方式缩小错误的潜在位置。接下来,启动 fiddler http 调试器并验证 http 请求。让我们知道您发现了什么!
Profile the sql statements that are arriving at sql server with sql server profile. You can narrow the potential locations of the bug that way. next, start the fiddler http debugger and verify the http requests. and let us know what you found!
在这里向我们展示您的代码会有所帮助。如果数据对象包含错误的值,则必须确定后端正在运行正确的 SP,并且如果适用,则必须将正确的参数传递到后端。您应该能够在 Visual Studio 调试器中单步执行调用。
It would help to show us your code here. If the data objects contain the wrong values, you have to demonstrate with certainty that the correct SPs are being run on the back end and, if applicable, that the correct parameters are being passed to the back end. You should be able to step through the call in the Visual Studio debugger.