Lesson 3: Processing Transactions
The purpose of this lesson is to recognize the existence of functionality in the .NET framework that can be considered transactional. However, it is clear that "real" (distributed) transactions are covered only by COM+ Enterprise Services. So the transaction features of ADO.NET 1.x are confined to a single connection object. The .NET Framework 2.0 context introduces the System.Transactions namespace. For more information please see "ADO.NET and System.Transactions" by John Papa here:
http://msdn.microsoft.com/msdnmag/issues/05/02/DataPoints/default.aspx
- "Database programmers determine what database commands belong in a transaction by using the ACID test..."
ACID stands for Atomic, Consistent, Isolated and Durable. For more details please see "The ACID Test: A mini database tutorial for those that are interested..." by John Parker here:
http://www.archwing.com/technet/technet_ACID.html
- "Transaction processing follows these steps: 1. Begin a transaction. 2. Process database commands. 3. Check for errors. 4. If errors occurred, restore the database to its state at the beginning of the transaction. If no errors occurred, commit the transaction to the database."
ADO.NET 1.x handles transactions implicitly and explicitly. DataSet methods Update(), RejectChanges() and AcceptChanges() imply transactional processing. Use of the SqlTransaction, OracleTransaction and OleDbTransaction objects explicitly handle transactions against one database connection. These transaction objects are obtained from the BeginTransaction() method of the connection object. Once the transaction object is obtained, the Commit() and Rollback() methods are used to design a transaction.
Command objects are associated with a connection. When a connection begins a transaction, all command objects referencing that connection must have their Transaction property set. An important quote from "Best Practices for Using ADO.NET" by Dennis Lu and Doug Rothaus: "If the Command.Transaction property is not set to a Transaction that has been started for the associated Connection, the Command fails and an exception is thrown." For more information see:
http://msdn.microsoft.com/library/en-us/dnadonet/html/adonetbest.asp
-
"The transaction object determines how concurrent changes to a database are handled through the IsolationLevel property."
-
"SQL database connections provide one transaction capability that is unavailable for OLE database connections: the ability to create save points within a transaction."
-
"Because transactions can span multiple Web forms, or even multiple components within a distributed application, ASP.NET provides a way for Web forms to work with MS DTC."
The Transaction attribute of the @Page directive starts a new transaction. The static methods of the System.EnterpriseServices.ContextUtil class are used to commit or abort MTS (or MS DTS) transactions in ASP.NET pages. These static methods are SetComplete() and SetAbort() (which correspond to Page events CommitTransaction() and AbortTransaction() respectively). For more information see "MTS Transactions" here:
http://samples.gotdotnet.com/quickstart/aspplus/doc/mtstransactions.aspx