TAILIEUCHUNG - Using ADO.NET and SQL Server DBMS Transactions Together

[ Team LiB ] Recip Using and SQL Server DBMS Transactions Together Problem You need to use a DBMS transaction within a SQL Server stored procedure from an transaction with the SQL Server .NET data provider. | Team LiB Recipe Using and SQL Server DBMS Transactions Together Problem You need to use a DBMS transaction within a SQL Server stored procedure from an transaction with the SQL Server .NET data provider. Solution Use error-checking within a catch block as shown in Example 6-5. The sample uses a single stored procedure InsertCategories_Transacted Used to insert a single record into the Categories table in the Northwind database within a DBMS transaction. If the record insert fails the transaction is rolled back otherwise the transaction is committed. The sample code contains two event handlers Sets up the sample by filling a DataTable with the Categories table from the Northwind sample database. The default view of the table is bound to a data grid on the form. Insert Inserts user-entered data for the Categories records into the Northwind database within a manual transaction using a DBMS transacted stored procedure. The transaction is rolled back in the stored procedure if either the Force DBMS Rollback checkbox is checked or if no value is entered for the Category Name field. Otherwise the manual transaction is committed. Example 6-5. Stored procedure InsertCategories_Transacted CREATE PROCEDURE InsertCategories_Transacted @CategoryId int output @CategoryName nvarchar 15 @Description ntext @Rollback bit 0 AS SET NOCOUNT ON begin tran insert Categories CategoryName Description values @CategoryName @Description if @@error 0 or @@rowcount 0 or @Rollback 1 begin rollback tran set @CategoryID -1 return 1 end commit tran set @CategoryID Scope_Identity select @CategoryID Categoryld return 0 The C code is shown in Example 6-6. Example 6-6. File Namespaces variables and constants using System using using using using private SqlDataAdapter da private DataTable dt . . . private void DbmsTransactionForm_Load object sender .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.