views:

205

answers:

2

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

A: 

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
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.
alhambraeidos
+1  A: 

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