15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

23<br />

system.Transactions<br />

WhaT ’ s in This ChaPTer<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

Transaction phases <strong>and</strong> ACID properties<br />

Traditional transactions<br />

Committable transactions<br />

Transaction promotions<br />

Dependent transactions<br />

Ambient transactions<br />

Transaction isolation levels<br />

Custom resource managers<br />

Transactions with Windows 7 <strong>and</strong> Windows Server 2008<br />

All or nothing — this is the main characteristic of a transaction. When writing a few records, either<br />

all are written, or everything will be undone. If there is even one failure when writing one record, all<br />

the other things that are done within the transaction will be rolled back.<br />

Transactions are commonly used with databases, but with classes from the namespace<br />

System.Transactions , you can also perform transactions on volatile or in - memory - based objects<br />

such as a list of objects. With a list that supports transactions, if an object is added or removed <strong>and</strong><br />

the transaction fails, the list action is automatically undone. Writing to a memory - based list can be<br />

done in the same transaction as writing to a database.<br />

Since Windows Vista, the fi le system <strong>and</strong> registry also get transactional support. Writing a fi le <strong>and</strong><br />

making changes within the registry supports transactions.<br />

oVerVieW<br />

What are transactions Think about ordering a book from a web site. The book - ordering process<br />

removes the book you want to buy from stock <strong>and</strong> puts it in your order box, <strong>and</strong> the cost of your<br />

book is charged to your credit card. With these two actions, either both actions should complete<br />

successfully or neither of these actions should happen. If there is a failure when getting the book from<br />

stock, the credit card should not be charged. Transactions address such scenarios.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!