从 SQL Server 数据库进行 AJAX 更新:返回的值不正确

发布于 2024-11-09 04:19:23 字数 824 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流绪微梦 2024-11-16 04:19:23

使用 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!

初心 2024-11-16 04:19:23

有时是读者
产生的值似乎是
从以前的 AJAX 中“缓冲”
交互,即我正在运行
正确的存储过程
变量,但返回值是
如果我跑得那么精确,那不是我得到的
SQL查询界面中的相同命令
- 它们是先前调用 SQL 连接、命令和的结果
读者都被创建并且
为每个重新实例化
相互作用并正确处置
通过 IDisposable 使用后
界面我已经更换了阅读器
对于数据集,没有区别
结果

在这里向我们展示您的代码会有所帮助。如果数据对象包含错误的值,则必须确定后端正在运行正确的 SP,并且如果适用,则必须将正确的参数传递到后端。您应该能够在 Visual Studio 调试器中单步执行调用。

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文