odbc 和 C++ 的异常问题 导致奇怪的数据库行为
我有一个 C++ 应用程序(使用 VS2003 编译,在 Windows 2000 服务器上针对 SQL 2000 数据库运行),该应用程序运行良好多年,但现在崩溃了。
我的日志记录显示数据库连接(使用 SQL Server 驱动程序的 ODBC)将正常工作(读取和更新数据库),然后在抛出异常(并被捕获/记录但没有真正的详细信息)后,连接可以从数据库读取数据,但是无法再更新数据库。
所以我看到一个线程正在读取下一行来处理,将数据从套接字发送到另一台服务器,尝试更新已处理的记录,然后就繁荣了。
我从失败的查询中得到的唯一错误信息是:
[Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. [37000]
后面跟着一个空白,就像您通常会看到查询失败的原因一样(语法错误,找不到表,无论如何,但这次没有)。
该代码处理数以万计的记录,可能会运行数月,并且在该线程(似乎总是第一个受害者,可能只是最忙并且最先被攻击)开始阻塞之后不久,所有其他连接似乎都有相同的问题 -允许读取,但更新会引发此异常。
上次我快速查看了任务管理器(它很快被弹起,所以我无法长时间检查),该应用程序使用典型的 5 到 6 Meg RAM,其他资源看起来很正常。
其他应用程序正在使用该数据库并且在此期间没有错误。
当查询有效时,我无法在网上找到任何获得此报告错误结果的内容...
帮助!
I have a C++ application (compiled with VS2003 running on windows 2000 server against SQL 2000 database) that ran fine for years and now is crashing.
My logging shows that the database connection (ODBC using the SQL Server driver) will be working fine (read and update database) then after an exception throws (and is caught/logged but no real detail) the connection can read data from the database but can no longer update the database.
So I see a thread is reading the next row to process, sending data out a socket to another server, tries to update the record as processed and BOOM.
The only error info I get back from the failed query is:
[Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. [37000]
followed by a blank like where you would normally see the reason the query failed (bad syntax, table not found, whatever, but this time nothing).
This code processes tens of thousands of records, may run for months and shortly after this thread (always seems to be the first victim, may just be the busiest and gets whacked first) starts choking all the other connections appear to have the same problem - read is allowed but updates throw this exception.
I got a quick look at the task manager the last time (it gets bounced quick so I can't examine for long) and the app was using the typical 5 to 6 Meg of RAM and the other resources looked normal.
Other applications are using the database and have no errors during this time.
I can't find anything online where you get this reported error result when the query is valid...
HELP!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据错误“[Microsoft][ODBC SQL Server Driver][SQL Server]无法准备语句。[37000]”,我假设 ODBC 驱动程序正在尝试准备语句。 这给我们带来了很多不稳定的问题。
在 ODBC 数据源的定义中,取消选中“为准备好的 SQL 创建临时存储过程...”选项,并查看这是否修复了错误。
From the error, "[Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. [37000]" I assume the ODBC Driver is trying to prepare a statement. This has caused us lot of erratic problems.
In the definition of the ODBC Data Source, uncheck the "Create temporary stored procedures for prepared SQL ... " option, and see if this fixes the error.
当不允许空值时,更新语句是否有可能写入对其字段来说太大的数据或空值?
也许您可以将更新记录到文件中,以确定问题是否是数据驱动的。
我不确定SQL Server的ODBC驱动程序是否使用ADO,但我认为ADO在其更新和插入代码中存在泄漏,这些代码将逐渐消耗您的所有内存。 如果在大约相同数量的记录后持续发生崩溃,您可能需要进行调查。
Any chance that the update statement is writing data too large for its field or null when nulls aren't allowed?
Perhaps you could log the updates to a file to determine if the problem is data-driven.
I'm not sure if SQL Server's ODBC driver uses ADO, but I think that ADO has a leak in its update and insert code that will gradually consume all of your memory. If you get the crash consistantly after approximately the same number of records, you may want to investigate.