【问题标题】:PRINT from nested stored procedure causes "A severe error occurred on the current command."嵌套存储过程中的 PRINT 导致“当前命令发生严重错误”。
【发布时间】:2011-10-04 15:44:50
【问题描述】:

从子存储过程调用 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.

服务器A: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) 

服务器 B: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 不阻塞。我还有其他情况,我从子存储过程调用 print,没有错误。

更新精简到最小的可重现情况。显示准确的sql

【问题讨论】:

    标签: sql-server sql-server-2000


    【解决方案1】:

    从 Management Studio 运行查询时似乎是 SQL 2000 的问题

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

    【讨论】:

    • 我挖出了一个 QA 版本。你是对的。谁会想到这是 SSMS 中的错误。
    猜你喜欢
    • 2014-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-02
    • 1970-01-01
    • 1970-01-01
    • 2016-10-12
    • 1970-01-01
    相关资源
    最近更新 更多