Rich Web client development with ASP.NET ,LINQ , WCF and now Silverlight2

Friday, December 26, 2008

Transactionscope

Transactionscope makes it easy to manage transactions in .Net even if they are only simple one database access or involve multiple resources such as sql servers or WCF services. However there are a few rules:
In order for a resource manager (in this case SQL Server) to take part inside a transaction it must first enlist in the transaction if one already exists, SQL server determines this when a connection is first opened. Opening a connection when there is a transaction associated with the current thread will result in SQL server placing that connection inside the existing transaction, if no other enlistment has happened then SQL server will create a local transaction
and thus manage the transaction. Only if multiple resources are involved will the Distributed Transaction Coordinator (DTC) be brought into the picture.
We initiate the Transaction as follows:

using (TransactionScope scope = new TransactionScope(opt))
where opt is one of:
Required Join the ambient transaction, or create a new one if one does not exist
RequiredNew start a new transaction inside its own scope
Suppress no transaction

see http://msdn.microsoft.com/en-us/library/ms172152.aspx for more

So unless we are accessing multiple transactionable resources in our scope the DTC should not be envoked. This is easily proved by adding a line of code like:

Guid guid = Transaction.Current.TransactionInformation.DistributedIdentifier

This will be null is we are using Suppress and all zeros if the DTC is not used. of course the transactions are not completed till scope.Complete() is called which will not be the case when
an exception is thrown and the changes to our resources are rolled back.

Labels:

Wednesday, December 24, 2008

Photo Application version 2

Just put up a new version of my photo application that uses a ListBox to hold the images .

http//www.sandkeysoftware.com/sl2/mypictures/MyPictures.Web/MyPicturesTestPage.html

Monday, December 08, 2008

calling WCF service from T-SQL

Just put a document on my website to describe this process:

http://www.sandkeysoftware.com/wcf/TSQLToWCF.pdf

Labels: