[英]Table of SQL Errors & Stored Procedures
I have this bit of code I found on the web at the end of each of my stored procedures: 在每个存储过程的结尾,我都有在网上找到的这段代码:
ROLLBACK TRANSACTION
PRINT '-----START: ERROR DETAILS-----'
PRINT ERROR_NUMBER()
PRINT ERROR_SEVERITY()
PRINT ERROR_STATE()
PRINT ERROR_PROCEDURE()
PRINT ERROR_LINE()
PRINT ERROR_MESSAGE()
PRINT '-----END: ERROR DETAILS-----'
DECLARE @prmErrmsg NVARCHAR(4000);
DECLARE @prmErrSvr INT;
SELECT @prmErrmsg = ERROR_MESSAGE()
,@prmErrSvr = ERROR_SEVERITY();
INSERT INTO dbo.myErrors
([ErrorMessage]
,[ErrorSeverity]
,[DateCreated])
VALUES
(@prmErrmsg
,@prmErrSvr
,GetutcDate())
RAISERROR(@prmErrmsg,@prmErrSvr,1)
It's writing entries to the myErrors table, but it's not writing an error message or an error severity. 它正在将条目写入myErrors表中,但未写入错误消息或错误严重性。
My first question is why? 我的第一个问题是为什么?
I believe it's got something to with the error severity being within a certain range. 我相信错误严重性在一定范围内是有好处的。
How can I tell it to log verbose error messages ALWAYS, regardless of severity? 我如何告诉它始终记录详细的错误消息,而不管其严重程度如何?
根据MSDN ,仅在TRY ... CATCH语句的CATCH块内设置ERROR_MESSAGE()等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.