TAILIEUCHUNG - Hướng dẫn học Microsoft SQL Server 2008 part 65

Để biết thêm chi tiết về giao dịch và xử lý lỗi, bao gồm một cuộc thảo luận về giao dịch bị tiêu diệt và xact_state việc () chức năng, xin vui lòng xem Chương 66,''quản trị giao dịch, khóa, và chặn.'' | Part IV Developing with SQL Server the case I recommend rolling back the transaction as the first action so that any locks the transaction might be holding are released. Er- - For more details on transactions and error handling including a discussion on doomed transactions and the xact_state function please refer to Chapter 66 Managing Transactions Locking and Blocking. 2. If the error is one that the stored procedure logic detects and it s not a SQL Server error then raise the error message so that the user or front-end application is informed. 3. Optionally log the error to an error table. 4. Terminate the batch. If it s a stored procedure user-defined function or trigger then terminate it with a RETURN command. When an error occurs in the TRY block and execution is passed to the CATCH block the error information is also passed to the CATCH block. The information may be examined using the error functions listed in Table 23-2. These functions are designed specifically for the CATCH block. Outside a CATCH block they will always return a null value. Catch Functions TABLE 23-2 Error Function Returns Error_Message The text of the error message Error_Number The number of the error Error_Procedure The name of the stored procedure or trigger in which the error occurred Error_Severity The severity of the error Error_State The state of the error Error_Line The line number within the batch or stored procedure that generated the error Xact_State Whether the transaction can be committed see Chapter 66 These CATCH functions retain the error information of the error that fired the CATCH block. They may be called multiple times and still retain the error information. The following sample demonstrates a CATCH block using the CATCH functions and a RAISERROR to report the error to the client. The contents of the error functions are being passed to variables so a custom error string can be assembled for the RAISERROR BEGIN CATCH DECLARE 602 T-SQL Error Handling

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.