I have some code which is doing something like this (please note that the actual code is much more complex). I have produced this to aid explanation:
Imports System.Data.SqlClient
Imports System.Transactions
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Using scope As New TransactionScope
Try
Dim objCon As SqlConnection = New SqlConnection("Connection string 1")
Dim objCon2 As SqlConnection = New SqlConnection("Connection string 2")
objCon2.Open()
Using objCon2
Dim t1 As New Test
t1.Test()
objCon.Open()
End Using
Catch ex As Exception
'I do not swallow exceptions
End Try
End Using
End Sub
End Class
Public Class Test
Public Sub Test()
Dim objCon1 As SqlConnection = New SqlConnection("Connection string 1")
objCon1.Open()
End Sub
End Class
The code above shows that I am connecting to two databases inside the transaction (one of them is connected to twice). Here is the exception: FormLoad error: System.Transactions.TransactionException: The partner transaction manager has disabled its support for remote/network transactions. (Exception from HRESULT: 0x8004D025).
See this SO post. The guy finds the answer to his question, and so much more.
transactionscope-with-multiple-database-connections
Definately a good read if working with TransactionScope.
User contributions licensed under CC BY-SA 3.0