如何忽略从 ASP 调用的 SQL Server 2000 过程中嵌套存储过程的错误
我正在开发一个带有 SQL Server 2000 数据库的“经典”ASP 应用程序。
我们有一个存储过程(我们称之为 SP0),它调用其他存储过程(比如 SP0.1、SP0.2 ...),而这些存储过程本身又调用另一个名为 SPX 的存储过程。
当使用 RAISERROR()
出现问题时,所有这些过程都会生成错误。
我们希望能够使用参数 @errorsInResultSet
启动 SP0,这将改变其行为:每个子过程都会将错误记录在临时表#DetectedProblems 并在最后返回它。
向临时表添加错误不是问题,但我不知道如何忽略嵌套存储过程生成的错误。
到目前为止我已经这样做了:
EXEC @rc = [SP0.1] @errorsAsResultSet = @errorsAsResultSet
IF (0 <> @@ERROR) OR (0 <> @rc)
BEGIN
IF (@errorsAsResultSet <> 0x1)
BEGIN
RAISERROR('SP0.1: Error for table Tests in db %s.%s', 16, 1, @@SERVERNAME, @db)
END
GOTO FAILURE
END
这工作正常,但它仍然从最低的 SPX 生成错误,这阻止了它在经典 ASP 中被 ADO 执行。
我怎样才能忽略这些错误?
I am working on a "classic" ASP application with a SQL Server 2000 database.
We have a stored procedure (let's call it SP0) that calls other stored procedures (let's say SP0.1, SP0.2 ...) which themselves call another stored procedure called SPX.
All those procedures generate errors when something goes wrong using RAISERROR()
.
We want to be able to launch SP0 with a parameter @errorsInResultSet
which will change its behaviour : instead of "re-raising" the errors as it does so far, each sub-procedure will log the errors in a temporary table #detectedProblems
and return it at the end.
Adding errors to the temporary table is not a problem, but I can not figure out how to ignore the errors generated by the nested stored procedures.
I have done this so far :
EXEC @rc = [SP0.1] @errorsAsResultSet = @errorsAsResultSet
IF (0 <> @@ERROR) OR (0 <> @rc)
BEGIN
IF (@errorsAsResultSet <> 0x1)
BEGIN
RAISERROR('SP0.1: Error for table Tests in db %s.%s', 16, 1, @@SERVERNAME, @db)
END
GOTO FAILURE
END
This works fine, but it still generate errors from the lowest SPX, which prevent it from being executed by ADO in classic ASP.
How can I ignore the errors ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您对记录错误感到满意并且可以安全地继续,则可以在 SP 调用之前的行上使用
ON ERROR RESUME NEXT
。这将防止页面抛出错误。要稍后在页面中重新显示错误,您可以使用
ON ERROR GOTO 0
If you're happy that the errors are being logged and it's safe to continue, you can use
ON ERROR RESUME NEXT
on the line before the SP call. This will prevent the page from throwing errors.To turn back on errors later in the page, you can use
ON ERROR GOTO 0
最后,看起来没有办法从调用存储过程中“隐藏”由 SP0.1、SP0.2 中的
PRINT
或RAISERROR
语句生成的消息,这意味着执行总是被 ASP 解释为“错误”。最后,我重写了一个新的存储过程,其中包含一个特殊的参数来配置如何报告错误。
In the end, it looks like there is no way to "hide" messages generated by
PRINT
orRAISERROR
statements in SP0.1, SP0.2 from the calling Stored Procedure, which means that the execution is always interpreted as "erroneous" by ASP.In the end, I rewrote a new Stored Procedure with a special parameter to configure how to report errors.