如何获取执行原生sql的错误信息
1 回答
拉风的咖菲猫
TA贡献1995条经验 获得超2个赞
获取代码如下:
BEGIN TRY
SELECT 3 / 0
END TRY
BEGIN CATCH
DECLARE @errornumber INT
DECLARE @errorseverity INT
DECLARE @errorstate INT
DECLARE @errormessage NVARCHAR(4000)
SELECT
@errornumber = ERROR_NUMBER() ,
@errorseverity = ERROR_SEVERITY() ,
@errorstate = ERROR_STATE() ,
@errormessage = ERROR_MESSAGE()
SELECT @errornumber ,
@errorseverity ,
@errorstate ,
@errormessage
RAISERROR (
@errormessage, -- Message text,
@errorseverity, -- Severity,
@errorstate, -- State,
@errornumber
);
END CATCH
- 1 回答
- 0 关注
- 962 浏览
添加回答
举报
0/150
提交
取消