4

I'm using WinXP on clients and Win2003 on a server.

I need do atomic actions: create-moving files, insert-update database.

Are there any good practices for file system transactions using WinXP? I know in Vista/Win2008/Win7 there are TxF transaction (NTFS) but not in WinXP.

I don't want use COM+, neither other complex solutions. Only need good sample code, for good practices.

Transactions and file-actions by Alberto Poblacion

In versions of Windows earlier than Vista, the filesystem is not transactional, so you need a separate tool to do transactions on your files.

You could use Component Services (COM+) to implement a Compensating Resource Manager (CRM). The CRM will provide the transaction log and will roll back changes during a system restart if it crashed during the update of your files, but you will have to provide the code (in your own DLL) to commit and rollback the transation, typically by means of moving files in and out of a temp folder. It can all be done in .Net by means of the System.EnterpriseServices namespace. If I recall correctly, Microsoft Official Course 2557 contains a chapter that teaches how to create a CRM, and the example that they use is built precisely on changes to the filesystem.

In newer versions of Windows, you can do transactional operations on NTFS:

http://msdn.microsoft.com/en-us/library/bb986748(VS.85).aspx

http://msdn.microsoft.com/en-us/magazine/cc163388.aspx

http://codeproject.com/KB/vista/VistaKTM.aspx

Edit.

References:

https://transactionalfilemgr.codeplex.com/

http://www.codeproject.com/Articles/690136/All-About-TransactionScope

http://ayende.com/blog/4528/who-stole-my-transaction

http://www.chinhdo.com/20080825/transactional-file-manager/

http://bmegias.wordpress.com/2010/10/25/ejecutar-acciones-al-finalizar-la-transaccion-transactioncompleted-vs-enlistvolatile/

Kiquenet
  • 14,494
  • 35
  • 148
  • 243

4 Answers4

2

You could create your own class that implements IEnlistmentNotification.

Here's an example of someone that did: http://www.chinhdo.com/20080825/transactional-file-manager/

ChrisNel52
  • 14,655
  • 3
  • 30
  • 36
  • Any full source code sample about it ? http://www.codeproject.com/Articles/690136/All-About-TransactionScope – Kiquenet Dec 02 '13 at 21:19
1

You might want to look at the File.Replace method which I think uses transactions since it requires NTFS. http://msdn.microsoft.com/en-us/library/9d9h163f(v=vs.100).aspx

Bryan Legend
  • 6,790
  • 1
  • 59
  • 60
0

The .NET Transactional File Manager should work under XP.

Out of interest, TxF is likely to be pulled from future releases of Windows (certain features have been deprecated in Win 8).

See How to write a transaction to cover Moving a file and Inserting record in database?.

Community
  • 1
  • 1
CJM
  • 11,908
  • 20
  • 77
  • 115
0

You won't get true filesystem transactions for NTFS in XP. That said, you may not need it.

For example, with software installation, you can largely get the semantics of transactions for free by using something like Windows Installer.

What is it you are looking to ultimately accomplish?

rh.
  • 1,731
  • 1
  • 10
  • 11
  • I want do this: move files from folder A to a folder B, and update database. If any error, rollback database and "rollback" c hanges in filesystem. Thanks. – Kiquenet Apr 23 '10 at 15:17