/*创建错误日志记录存储过程*/ CREATE PROCEDURE InsErrorLog AS BEGIN INSERT INTO ErrorLog SELECT ERROR_NUMBER() AS ErrNum, ERROR_SEVERITY()AS ErrSev, ERROR_STATE() AS ErrState, ERROR_PROCEDURE() AS ErrProc, ERROR_LINE()AS ErrLine, ERROR_MESSAGE()AS ErrMsg END 3、在存储过程中使用BEGIN TRY,并捕捉错误保存:
CREATE PROCEDURE GetErrorTest AS BEGIN TRY /*在这里填写存储过程的内容*/ *** END TRY BEGIN CATCH EXEC InsErrorLog --调用 InsErrorLog 存储过程,保存错误日志 END CATCH