Transaction management met ADO.NET 2.0

Vroeger, het klinkt al lang geleden, maakten transacties onderdeel uit van Enterprise Services.
Om transactions te gebruiken in het .NET Framework 2.0 is het, net als in .NET 1.x, noodzakelijk om eerst een externe referentie te leggen naar een system assembly. In In het .NET Framework 2.0 is er echter een nieuwe assembly bijgekomen en wel de System.Transactions.dll. Binnen Microsoft wordt deze functionaliteit gezien als onderdeel van Indigo, en eigenlijk zien we hier dus de eerste Indigo functionaliteit verschijnen.

System.Transactions biedt nieuwe oplossingen voor het managen van transactions. Onderstaand code voorbeeld geeft aan hoe het werkt.

using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOptions.RequiresNew))
{
//Delegation only works against Sql Server 2005,
//for this example to work this connection must point to one.
using (SqlConnection conn1 = new SqlConnection(_connectionStringYukon))
{
conn1.Open(); //The connection enlists, but does not promote
//do your work 1 here.
}
MessageBox.Show("Check your Transaction Statistics Active transactions here, then press enter");
//This connection can point to any Backend that supports DTC.
//Sql Server 7, 2000, 2005 or Oracle
using (SqlConnection conn2 = new SqlConnection(_connectionString2))
{ conn2.Open();
//The connection enlists, and automatically promotes the transaction.
//do your work 2 here.
if ( error == true )
{ System.
Transactions.Transaction.Current.Rollback();
}
}
MessageBox.
Show("Check your Transaction Statistics Active transactions here, then press enter");
// Set the scope to complete
transactionScope.Complete();
}

Het is niet meer nodig om te erven van ServicedComponent. Transacties kunnen hierdoor qua scope veel nauwkeuriger gemanaged worden. Wat verder bijzonder aan dit voorbeeld is, is dat de transactie ook nog ‘slim’ is. Op het moment dat ‘conn1.Open()’ wordt aangeroepen wordt wel een transactie gestart, maar de DTC nog niet geactiveerd; immers, dit is de eerste datasource die aangesproken wordt, dus er is nog geen sprake van een distributed transaction. Op het moment dat ‘conn2.Open()’ wordt uitgevoerd, is de transaction slim genoeg om te detecteren dat het hier om een andere datasource gaat, en wordt alsnog de DTC bijgeschakeld. Deze functionaliteit is momenteel (beta 1, CTP december) alleen beschikbaar voor Yukon (SQL Server 2005).

Commentaar van anderen:
ChristianLouboutin op 14-8-2010 om 10:44
Christian Louboutin Shoes, Christian Louboutin, Christian Louboutin Shoes, Wedding Shoes, Christian Louboutin Copyright 2010, Chemicals Chemistry via VerticalNews. Christian Louboutin Shoes, Wedding Shoes Pattinson great actorly virtue is that he wears clothes well, so it too bad he slackered-out in cargo pants here. Christian Louboutin, Christian Louboutin Shoes, Wedding Shoes, Discount Christian Louboutin, Manolo Blahnik Shoes Tyler is less revealed than telegraphed through accessories a dead brother depth, a pack-a-day habit angst, a bookstore job smart, Discount Christian Louboutin, Louboutin, Christian Louboutin Sale, Louboutin Shoes, Sale Christian Louboutin Rodita zip sandals New style Black 14 a rich, aloof, and permanently disappointed daddy Pierce Brosnan. Louboutin Sale, Herve Leger Bandage Dress, Herve Leger Dress, Herve Leger V Neck Dress, Herve Leger Bandage Dress Falling for You Love, angst, and something else is in the air in Remember Me Remember Me Herve Leger Dress, Chanel Shoes, Yves Saint Laurent Shoes, Manolo Blahnik Shoes Platform Cage Sandal 13 by Allen Coulter Summit Entertainment Opens March 12 Putatively a new romance starring Robert Pattinson, Remember Me begins like a vigilante movie Alexander Wang Shoes, Louboutin Shoes, Louboutin Sale, Louboutin, Christian Louboutin Sale, Buy Christian Louboutin A Brooklyn subway platform, a racially charged stickup girl watches her mother get shot. Christian, Christian Louboutin Discount, Christian Dior Shoes, Christian Louboutin Pumps Pattinson great actorly virtue is that he wears clothes well, so it too bad he slackered-out in cargo pants here.
Geef feedback:

CAPTCHA image
Vul de bovenstaande code hieronder in
Verzend Commentaar