来自嵌套存储过程的 PRINT 导致“当前命令发生严重错误。”
从子存储过程调用 PRINT
会导致:
消息 0,级别 11,状态 0,第 0 行
当前命令发生严重错误。结果(如果有)应被丢弃。
怎么让它不报错呢?
我有一个存储过程
ALTER PROCEDURE [dbo].[Archive_SessionDeleteOnly] AS
SET XACT_ABORT ON
BEGIN DISTRIBUTED TRANSACTION
EXECUTE ASILIVE.ContosoLive.dbo.Archive_Delete
ROLLBACK TRANSACTION
PRINT 'Fargodeep Mine'
,子存储过程是:
ALTER PROCEDURE [dbo].[Archive_Delete] AS
PRINT 'You no take candle'
当我运行外部过程时Archive_SessionDeleteOnly
它全部运行到完成,包括调用我的子存储过程之后的PRINT
You no take candle
Fargodeep Mine
Msg 0, Level 11, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.
整个操作运行到完成,但我得到一个错误:
Msg 0, Level 11, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.
如果我从“子”存储过程中删除 print
:
ALTER PROCEDURE [dbo].[Archive_Delete] AS
--PRINT 'You no take candle'
它运行时不会出现错误。
我还尝试随机添加 NOCOUNT
(因为没有人知道如何修复它):
ALTER PROCEDURE [dbo].[Archive_Delete] AS
SET NOCOUNT ON
PRINT 'You no take candle'
它仍然会导致:
Msg 0, Level 11, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.
ServerA: SQL Server 2000
SELECT @@version
Microsoft SQL Server 2000 - 8.00.818 (Intel X86) May 31 2003 16:08:15 Copyright (c) 1988-2003 Microsoft Corporation Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 2)
ServerB: SQL Server 2000
SELECT @@version
Microsoft SQL Server 2000 - 8.00.2055 (Intel X86) Dec 16 2008 19:46:53 Copyright (c) 1988-2003 Microsoft Corporation Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 2)
SQL Server 错误日志中都没有错误。
当在子存储过程中使用 PRINT
时,如何使 SQL Server 不被阻塞。我还有其他情况,我从子存储过程调用打印,没有错误。
更新 修剪到最小的可重现案例。显示精确的sql
Calling PRINT
from a child stored procedure causes:
Msg 0, Level 11, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.
How to make it not give an error?
Note: Not SQL Server 2005
i have a stored procedure
ALTER PROCEDURE [dbo].[Archive_SessionDeleteOnly] AS
SET XACT_ABORT ON
BEGIN DISTRIBUTED TRANSACTION
EXECUTE ASILIVE.ContosoLive.dbo.Archive_Delete
ROLLBACK TRANSACTION
PRINT 'Fargodeep Mine'
With the child stored procedure being:
ALTER PROCEDURE [dbo].[Archive_Delete] AS
PRINT 'You no take candle'
When i run my outer procedure Archive_SessionDeleteOnly
it all runs to completion, including the PRINT
after the call to my child stored procedure
You no take candle
Fargodeep Mine
Msg 0, Level 11, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.
The entire operation runs to completion, but i get an error:
Msg 0, Level 11, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.
If i remove the print
from the "child" stored procedure:
ALTER PROCEDURE [dbo].[Archive_Delete] AS
--PRINT 'You no take candle'
it runs without error.
i've also tried randomly adding NOCOUNT
(since nobody knows how to fix it anyway):
ALTER PROCEDURE [dbo].[Archive_Delete] AS
SET NOCOUNT ON
PRINT 'You no take candle'
it still causes:
Msg 0, Level 11, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.
ServerA: SQL Server 2000
SELECT @@version
Microsoft SQL Server 2000 - 8.00.818 (Intel X86) May 31 2003 16:08:15 Copyright (c) 1988-2003 Microsoft Corporation Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 2)
ServerB: SQL Server 2000
SELECT @@version
Microsoft SQL Server 2000 - 8.00.2055 (Intel X86) Dec 16 2008 19:46:53 Copyright (c) 1988-2003 Microsoft Corporation Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 2)
There are no errors in either SQL Server Error Log.
How can i make SQL Server not choke when a PRINT
is used in a child stored procedure. i have other cases where i call print from child stored procedures, without error.
Update Trimmed down to minimal reproducible case. Exact sql is shown
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当从 Management Studio 运行查询时,似乎是 SQL 2000 的问题
您是否尝试过在查询分析器中运行它?
Seems to be an issue with SQL 2000 when the query is run from Management Studio
Have you tried running it in Query Analyzer?