是什么导致 SQL Server 返回消息“语句已终止"? [英] What causes SQL Server to return the message 'The statement has been terminated'?

查看:51
本文介绍了是什么导致 SQL Server 返回消息“语句已终止"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 Linux Apache Web 服务器上运行的 PHP 脚本执行了一个非常简单的 INSERT 语句.我可以在 SQL Management Studio 中正常运行查询,它通常也可以在 PHP 中正常运行.但是,每隔一段时间我就会从 PHP 脚本中收到一条错误消息,指出查询失败并且 mssql_get_last_message() 函数返回语句已终止".

I have a very simple INSERT statement being executed from a PHP script running on a Linux Apache web server. I can run the query fine from within SQL Management Studio and it normally runs fine from PHP as well. However, every once in awhile I get an error message from my PHP script that the query failed and the mssql_get_last_message() function returns 'The statement has been terminated'.

哪些来源会导致 SQL Server 返回此消息?

What sources can cause this message to be returned from SQL Server?

推荐答案

您发现了 SQL Server 中最烦人的部分之一.在某些情况下可能会引发错误,并且 SQL 将生成两条错误消息:第一个解释错误是什么,第二个说一些有用的信息,例如语句已终止"(从技术上讲,它是错误号3621).问题是 SQL 以及大多数与它相关的其他所有内容(例如 PHP)只能查看/获取/处理/或以其他方式利用最后一个未显示的错误消息.真正有用的会丢失.

You have found one of the most annoying parts of SQL Server. There are situations where an error can be raised, and SQL will generated two error messages: the first to explain what the error was, and the second to say something useful like "The statement has been terminated" (which, technically, is error number 3621). The thing is that SQL, and most everything else that touches it--such as PHP--can only see/pick up/process/or otherwise utilize that last unlcear error message. The one that's actually useful gets lost.

找出发生了什么的快速方法是运行导致 SSMS 错误的命令序列.显然,这对您不起作用.

The quick way to figure out what's going on is to run the sequence of commands leading up to the error from SSMS. This, apparently, will not work for you.

一种更复杂的解决方法是启动 SQL Profiler 来跟踪异常事件,然后运行您的进程.这应该显示发生的所有错误.加入相关的其他事件(SP:Starting、SP:StmtStarting、SQL:BatchStarting,任何适用于您提交到数据库的代码)将显示哪个命令引发错误.

A fussier way to figure it out is to fire up SQL Profiler to track the Exception event, and then run your process. This should show all errors that occured. Tossing in relevant other events (SP:Starting, SP:StmtStarting, SQL:BatchStarting, whatever is applicable to the code your submitting to the database) will show which command is raising the error.

这篇关于是什么导致 SQL Server 返回消息“语句已终止"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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