2

Consider the following code:

try
{
    using(TransactionScope)
    {
       Process.Start("SQLInstaller.EXE");
       throw new Exception();
       Commit();
    }
}
catch(Exception ex)
{
//Do something here
}

Will the changes made by SQLInstaller.exe be rollback in this scenario? More specifically, will the changes made by an external process launched through Process.Start() be handled by TxF?

Thanks!

Ian
  • 5,625
  • 11
  • 57
  • 93
  • What is `using(TransactionScope)`? – Darin Dimitrov Jun 01 '10 at 16:00
  • @Darin: A pseudocode for the actual Transaction object being used by TxF. http://msdn.microsoft.com/en-us/magazine/cc163388.aspx#S6 – Ian Jun 01 '10 at 16:04
  • 1
    @Darin: It's a class in the System.Transactions namespace. While a `TransactionScope` is active, Microsoft-provided objects that support transactions will automatically enlist in the "current" in-scope transaction (promoting it to a distributed transaction if necessary.) Some 3rd-party components will also support it, and you can auto-enlist your own objects if you choose to do so. When the `TransactionScope` is disposed, if the `Complete()` method has not been called, all enlisted transactions are automatically rolled back. – Toby Jun 01 '10 at 16:17
  • I don't have a good answer for you but the Distributed Transaction Coordinator (DTC) may be of assistance. – Steve Guidi Jun 01 '10 at 16:23
  • The answer is no, because the LTM/Lightweight Transaction Manager will not be used by SQLInstaller and a TransactionScope/CommittableTransaction is NOT promoted to a distributed transaction because it first needs to know what should be distributed (OleTx). Furthermore, TxF don't mesh well with other resource managers in a single distributed transaction, because MSDTC cannot guarantee the roll-back-ability of things in C:\system, unless the first resource manager to enlist the file transaction is KTM (i.e. you can enlist sql-tx afterwards for example and then DTC is a subordinate resource m.). – Henrik Apr 18 '11 at 12:44

3 Answers3

1

The starting process will not automagically do its work with transactions.

This is really a question of whether the model is implicit or explicit. We chose an explicit model specifically because an implicit model is extremely hard to reason about. Consider, for example, what it would be like if the created process went off and made an RPC call that didn't pipe the transaction through: would RPC client and server have consistent views of the world?

Short answer: nope.

jrtipton
  • 2,449
  • 1
  • 15
  • 9
0

Doubtful. The external process has absolutely no knowledge of your transaction scope. If you were the coder of the external process and had a way to pass around the transaction handle, sure, but in this case, highly unlikely.

Jesse C. Slicer
  • 19,901
  • 3
  • 68
  • 87
0

Everything will depend on how the file handle is obtained. If you open the file with a simple File.OpenWrite or any of the standard .NET file manipulation methods then you can be pretty sure that its access will not be transactional. CreateFileTransacted needs to be used every time you try to open a handle.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928