Microsoft ADO .NET 4 Step by Step - p 24

Lưu ý tập thể dục này sử dụng "Chương 12 CSharp" dự án mẫu và tiếp tục từ nơi tập thể dục trước trong chương này rời đi. 1. Mở mã cho các lớp AccountTransfer. Xác định vị trí chức năng TransferDistributed. | 206 Microsoft 4 Step by Step Processing with a Distributed Transaction C Note This exercise uses the Chapter 12 CSharp sample project and continues from where the previous exercise in this chapter left off. 1. Open the code for the AccountTransfer class. Locate the TransferDistributed function. This code performs a transfer between two bank account records using a distributed transaction. The body of the routine hosts two nested using blocks. ----- Create the withdrawal and deposit connections. using SqlConnection sourceLink new SqlConnection GetConnectionString using SqlConnection destLink new SqlConnection GetConnectionString ----- Lots of database-related code here. 2. Surround the two nested using blocks with a third outer using block. using TransactionScope envelope new TransactionScope ----- The two original nested using blocks appear here. This statement block creates the TransactionScope which is the object responsible for managing the distributed transaction. 3. Just after the Transfer complete. Commit the transaction comment add the following line This method call commits the entire transaction. 4. Run the program. In the local-transaction sample earlier in this chapter attempting to overdraw funds caused the transaction to fail in the first half of the two-part update the withdrawal portion. You can force a failure in the second half of the transaction by selecting a transfer in the opposite direction and entering a negative value with an absolute value that exceeds the target account in the Transfer Amount field. Select From Savings To Checking as the transfer type and enter -1000 negative 1000 in the Transfer Amount field or any value that if positive would exceed the balance in the checking account. Select the Use A Distributed Transaction field and then click Transfer. The error that occurs triggers a rollback of the distributed transaction due to a check constraint failure in the deposit portion the second half of the .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.