Database Transactions

Database transactions are used to control data being committed to a database. This is typically done to safeguard against invalid data (which can be caused by many factors), power failures, or system crashes. As in ADO, transactions in ADO.NET are handled at the database level so the database you are using must support transactions.

Begin, Commit, and Rollback methods are now a part of the Transaction object. Begin marks the beginning of the transaction and includes anything until the next command—either Commit or Rollback. The code sample in Listings 9.33 and 9.34 tries to insert two records into the TitleAuthors table. If the page is executed more than once, the rollback behavior will be displayed.

Listing 9.33. Using ...

Get Special Edition Using® Microsoft® ASP.NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.