嵌套存储过程的PRINT导致“当前命令发生严重错误”。

时间:2011-10-04 15:44:50

标签: sql-server sql-server-2000

从子存储过程调用PRINT会导致:

  

消息0,级别11,状态0,行0   当前命令发生严重错误。结果(如果有的话)应该被丢弃。

如何让它不出错?

注意: Not SQL Server 2005


我有一个存储过程

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

1 个答案:

答案 0 :(得分:2)

从Management Studio

运行查询时,似乎是SQL 2000的问题

您是否尝试在查询分析器中运行它?