在執行 DBCC CHECKDB 時,如果發生不一致的狀況,是不會引發例外的,所以使用 TRY CATCH 是無法抓到這個錯誤,必須改用其它方式,
BEGIN TRY
DECLARE @Return INT
EXEC @Return = sp_executesql N'DBCC CHECKDB(''
IF @Return <> 0 RAISERROR ('Database corrupt', 11, 1)
END TRY
BEGIN 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;
END CATCH
原廠 KB 文章請參考: 這裡##ShowAll##
0 意見:
張貼留言