Transactions

Transactions are some statements with some work to be done wich must complete all successfully or all if one fail all must be drawn back.

Acid is a set of properties that guarantees that the transactions are executed reliable

atomic
if one part fails - everything fails
consistent
any transaction must leave the database is a valid state, anytime
isolated
ensures that the concurrent execution of transactions results in a system state like it was exectuted serially
durability
if a transaction has been committed it will remain so, no way back

transactions come out of: system.transactions namespace. We know the following types of transactions:

Simple transactions
your applications write to a database and if everythings is inserted or updated the transactions is ok.
Distributed transactions
transactions with multiple connections of different type of connections

Isolation levels

there are two isolationlevel enums: one in system.data and one in system.transaction. Both have the same values.Isolationlevel enum values.

unspecified
transaction is executed according the isolatition level determined by the driver.
chaos
not supported in sql or oracle, pending changes from highly isolated transactions cannot be overwritten.
readuncommitted
not shared locks, no exclusive locks, a dirty read of data can happen, undesirable.
readcommitted
shared locks are held, no dirty reads, data can be changed before the end of the transaction causing nonrepeatable reads.
repeatableread
locks are used on all data preventing other from updating any data.
serializable
a range lock is placed on a dataset. now one else can update until transaction is complete.
snapshot
an effictive copy of data, one version can read while the other can update. the size can cause problems if overused.

Transactionscope lives in system.transactions. It has a mehtod: complete. This method you have to call when you are complete, it tells the transaction manager to commit all data. If it isn't called, or there is some kind of exception ( if transactionscope is ued with a using statement ) the transactions is rolledback. The transactionscope class can handle simple transactions and distributed full distributed transactions, depended of commands inside the using transaction statement. It automatically scales up from simple transaction to distributed transactions. Everything is rollbacked ( if the system supports rollbacked, fi a send email cannot be rolled back ). Example transactions scope:

 
using (TransactionScope CurrentScope = new TransactionScope())
{
	try
	{
		Context.SaveChanges();
		CurrentScope.Complete();
	}
catch (EntityCommandExecutionException)
{
	//Handle the exception as you normally would
	//It won't be committed so transaction wise you're done
}

 

{{opmerking.Naam}}:

{{opmerking.OpmerkingText}}

            

Saving your comment....

Naam is verplicht!
Email is verplicht!
Opmerking is verplicht!