SQL Server存储过程返回'fail'

时间:2012-09-26 15:39:47

标签: asp.net sql-server-2008 stored-procedures

我在SQL Server 2008中有一个需要删除几行数据的存储过程。但是当我运行它时,它会返回一个失败,值为-6。

ALTER procedure [dbo].[p_CaseFiles_Exhibits_DeleteExhibits]
  @ExhibitID int
, @Message nvarchar(50) output
as
declare @FileID int
set @FileID = (select FileID from CaseFileExhibits where ExhibitID = @ExhibitID)
begin transaction
  begin try
    delete from CaseFileExhibitMovementTracking where ExhibitID = @ExhibitID
    delete from CaseFileExhibitAttachments where CaseFileExhibitID = @ExhibitID
    delete from CaseFileExhibits where ExhibitID = @ExhibitID
    delete from CaseFileExhibitPropertyLink where ExhibitID = @ExhibitID
    update CaseFileQuickStats set ExhibitCount = ExhibitCount -1 where CaseFileID = @FileID    
    commit transaction
  end try
  begin catch
    set @Message='Fail'
    rollback transaction
  end catch

我似乎无法找到错误。

1 个答案:

答案 0 :(得分:3)

您可以自己查看邮件,将其添加到您的CATCH块:

SELECT
ERROR_NUMBER() AS ErrorNumber
        ,ERROR_SEVERITY() AS ErrorSeverity
        ,ERROR_STATE() AS ErrorState
        ,ERROR_PROCEDURE() AS ErrorProcedure
        ,ERROR_LINE() AS ErrorLine
        ,ERROR_MESSAGE() AS ErrorMessage;

您可能希望将SELECT更改为PRINT,然后在SSMS中运行SP时,您将能够在“消息”选项卡中看到结果。

我怀疑外键或可能的触发器存在问题。