We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

TransactionScope and file creation

Medium Priority
1,304 Views
Last Modified: 2012-05-06
Is it possible to use TransactionScope for a combination of Db and file creation work?

Eg:

Private Sub MySub()
    Using scope As TransactionScope = New TansactionScope(TransactionScopeOption.Required)

                 ' 1)do some db work, Insert, update, delete

                 ' 2) create a file

                '  3) do some more db work

                scope.complete
     End Using

End Sub

Db is 2005.

At the present moment  TransactionScope works great for the Db side of things, but if, in above example, step 3) fails I'd like file creation to rollback not just the db stuff?
Comment
Watch Question

Commented:
Unfortunately the file system does not participate in transaction coordination.  
Commented:
Attach a handler for the TransactionCompleted event, and check if the transaction status is aborted.  If it is, then the transaction was rolled back, and you need to delete the file.
    Private Sub MySub()
        Using scope As TransactionScope = New TransactionScope(TransactionScopeOption.Required)
            AddHandler Transaction.Current.TransactionCompleted, AddressOf Current_TransactionCompleted
            ' 1)do some db work, Insert, update, delete
 
            ' 2) create a file
 
            '  3) do some more db work
 
            scope.Complete()
        End Using
 
    End Sub
 
    'Transaction completed event handler
    Private Shared Sub Current_TransactionCompleted(ByVal sender As Object, ByVal e As TransactionEventArgs)
        If e.Transaction.TransactionInformation.Status = TransactionStatus.Aborted Then
            'Delete your file here.
        End If
        
    End Sub

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Whilst not ideal this the proposed solution is working out quite well for us.  Thanks

Commented:
>Whilst not ideal this the proposed solution is working out quite well for us. Thanks

Regarding the B grade, I think I answered the question clearly and completely.  http://www.experts-exchange.com/help.jsp?hi=97

Author

Commented:
Apologies - pretty new to EE and hadn't read the "Help",  will be more accurate next time and happy change the B if possible.  I'll investigate.

Commented:
If you click on "Request Attention" at the top of your question, the moderators should be able to fix it.  Thanks.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.