TransactionScope and file creation

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?
invirlAsked:
Who is Participating?
 
PaulHewsConnect With a Mentor 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

0
 
dqmqCommented:
Unfortunately the file system does not participate in transaction coordination.  
0
 
invirlAuthor Commented:
Whilst not ideal this the proposed solution is working out quite well for us.  Thanks
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
PaulHewsCommented:
>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
0
 
invirlAuthor 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.
0
 
PaulHewsCommented:
If you click on "Request Attention" at the top of your question, the moderators should be able to fix it.  Thanks.
0
All Courses

From novice to tech pro — start learning today.