Home All Groups Group Topic Archive Search About

Transactionscope doesn't roll back

Author
2 Jul 2009 7:45 PM
Lubomir

..NET 3.5, Vista Bussiness 64

Hi,

I am calling an WCF service (netNamedPipeBinding, a locally running service)
from Windows form application. During the connection to the service, I am
executing a method, that contains a transaction:

using (TransactionScope scope = new TransactionScope ( ))
{
   try
   {
      doSomething1();
      doSomething2();
      doSomething3();
      scope.Complete();
   }
   catch (Exception)
   {
   }

}

When error occures in doSomething2(), exception is caught and the execution
will leave the TransactionScope block.

The doSomething1() is not rolled back as expected. In doSomething1() I am
creating some files on HDD and I expected these files will be automatically
deleted if transaction is not completed.

What am I missing?

Thanks,
Lubomir

Author
3 Jul 2009 11:27 AM
jesse.houwing
Hello Lubomir,

Show quoteHide quote
> .NET 3.5, Vista Bussiness 64
>
> Hi,
>
> I am calling an WCF service (netNamedPipeBinding, a locally running
> service) from Windows form application. During the connection to the
> service, I am executing a method, that contains a transaction:
>
> using (TransactionScope scope = new TransactionScope ( ))
> {
> try
> {
> doSomething1();
> doSomething2();
> doSomething3();
> scope.Complete();
> }
> catch (Exception)
> {
> }
> }
>
> When error occures in doSomething2(), exception is caught and the
> execution will leave the TransactionScope block.
>
> The doSomething1() is not rolled back as expected. In doSomething1() I
> am creating some files on HDD and I expected these files will be
> automatically deleted if transaction is not completed.
>
> What am I missing?

First of all, only a number of specific operations actually enrol in a transaction,
writing to a file isn't one of them.

second of all, if you don't tell the transactionscope to roll back, it will
not roll back, unless an exception is unhandled within the scope.

As you are handling (actually swallowing) the exception with your catch block,
nothing will be rolled back. To fix this:

try
{
using (TransactionScope scope = new TransactionScope ( ))
{
   doSomething1();
   doSomething2();
   doSomething3();
}
}
catch (Exception e)
{
   ///Handle exception in here
}

But as I said before, this will not roll back bytes written to a file.
--
Jesse Houwing
jesse.houwing at sogeti.nl
Are all your drivers up to date? click for free checkup

Author
4 Jul 2009 10:41 PM
Mr. Arnold
Show quote Hide quote
"Lubomir" <Lubo***@discussions.microsoft.com> wrote in message
news:F3D55DB1-2D6D-4099-B8AD-12429A9C58C1@microsoft.com...
> .NET 3.5, Vista Bussiness 64
>
> Hi,
>
> I am calling an WCF service (netNamedPipeBinding, a locally running
> service)
> from Windows form application. During the connection to the service, I am
> executing a method, that contains a transaction:
>
> using (TransactionScope scope = new TransactionScope ( ))
> {
>   try
>   {
>      doSomething1();
>      doSomething2();
>      doSomething3();
>      scope.Complete();
>   }
>   catch (Exception)
>   {
>   }
>
> }
>
> When error occures in doSomething2(), exception is caught and the
> execution
> will leave the TransactionScope block.
>
> The doSomething1() is not rolled back as expected. In doSomething1() I am
> creating some files on HDD and I expected these files will be
> automatically
> deleted if transaction is not completed.

It's not going to happen. Deleting files from a HDD is not a transaction.
Transactions are used to persist CURD operations in a transactional state
across databases, as an example.

You'll need to delete the files first, and do any clean-up for files that
have been created prior to the Exception, in the Exception handling
yourself.

The file deletion of the files should be done first prior to executing code
that's in a true transactional state, like for a database.



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4217 (20090704) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
Author
6 Jul 2009 1:09 AM
Herfried K. Wagner [MVP]
"Mr. Arnold" <MR. Arn***@Arnold.com> schrieb:
>> The doSomething1() is not rolled back as expected. In doSomething1() I am
>> creating some files on HDD and I expected these files will be
>> automatically
>> deleted if transaction is not completed.
>
> It's not going to happen. Deleting files from a HDD is not a transaction.
> Transactions are used to persist CURD operations in a transactional state
> across databases, as an example.

Vista supports transactional file operations.  I have written a wrapper
which is available from my website.  It will work with both KTM and DTC.

<URL:http://dotnet.mvps.org/dotnet/samples/filesystem/#Transactions>
-> 'Transactions.zip'

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
9 Jul 2009 6:19 PM
Mr. Arnold
Show quote Hide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:eb76vZd$JHA.200@TK2MSFTNGP05.phx.gbl...
> "Mr. Arnold" <MR. Arn***@Arnold.com> schrieb:
>>> The doSomething1() is not rolled back as expected. In doSomething1() I
>>> am
>>> creating some files on HDD and I expected these files will be
>>> automatically
>>> deleted if transaction is not completed.
>>
>> It's not going to happen. Deleting files from a HDD is not a transaction.
>> Transactions are used to persist CURD operations in a transactional state
>> across databases, as an example.
>
> Vista supports transactional file operations.  I have written a wrapper
> which is available from my website.  It will work with both KTM and DTC.
>
> <URL:http://dotnet.mvps.org/dotnet/samples/filesystem/#Transactions>
> -> 'Transactions.zip'
>

I tried to go to this site, and I am unsuccessful.



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4229 (20090709) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Bookmark and Share