|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Transactionscope doesn't roll backHi, 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 Hello Lubomir,
Show quoteHide quote > .NET 3.5, Vista Bussiness 64 First of all, only a number of specific operations actually enrol in a transaction, > > 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? 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
Show quote
Hide quote
"Lubomir" <Lubo***@discussions.microsoft.com> wrote in message It's not going to happen. Deleting files from a HDD is not a transaction. 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. 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 "Mr. Arnold" <MR. Arn***@Arnold.com> schrieb: Vista supports transactional file operations. I have written a wrapper >> 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. 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/>
Show quote
Hide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message I tried to go to this site, and I am unsuccessful.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' > __________ Information from ESET NOD32 Antivirus, version of virus signature database 4229 (20090709) __________ The message was checked by ESET NOD32 Antivirus. http://www.eset.com
Other interesting topics
Alternative to strongly typed datasets
static classes are evil ? System.Windows.Forms.Control.Handle==HWND? Getting started with a Kiosk-like application Uisng ADO.Net The Entity Framework How to open menu programmatically Pass Variable At Design Time Read From Application Config File In Class Library Form transparency setting the value to the combo box |
|||||||||||||||||||||||