Configuring MSDTC on Client PCs

I have an application which uses an implicit transaction using Transaction Scope when edits are saved to the SQL 2K server. MSTDC must be enabled on the client PC. Can someone please provide me with an example of how I can programmatically configure the client PC MSDTC settings for them? Right now users are instructed to manually perform the MSDTC configuration steps from the Component Manager in the Control Panel.

Thanks!

Corey

[612 byte] By [CoreyMc] at [2007-12-24]
# 2
Perfect. Thanks!
CoreyMc at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Transactions Programming...
# 3

I actually discovered what I needed was to modify the registry. Here is the code I used. Hope someone finds it useful.

Imports Microsoft.win32

Module SampleModule

Friend Sub ConfigMSDTCSettings()

Dim readRegKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\MSDTC\\Security", False)

Dim writeRegKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\MSDTC\\Security", True)

Dim changedItem As Boolean = False

Try

Dim networkDtcAccess As Integer = readRegKey.GetValue("NetworkDtcAccess", 0)

If networkDtcAccess = 0 Then

writeRegKey.SetValue("NetworkDtcAccess", 1)

changedItem = True

End If

Dim networkDtcAccessOutbound As Integer = readRegKey.GetValue("NetworkDtcAccessOutbound", 0)

If networkDtcAccessOutbound = 0 Then

writeRegKey.SetValue("NetworkDtcAccessOutbound", 1)

changedItem = True

End If

Dim networkDtcAccessTransactions As Integer = readRegKey.GetValue("NetworkDtcAccessTransactions", 0)

If networkDtcAccessTransactions = 0 Then

writeRegKey.SetValue("NetworkDtcAccessTransactions", 1)

changedItem = True

End If

If changedItem = True Then

MessageBox.Show("ToolName must update you system MSDTC settings. Please wait.", "MSDTC Update", MessageBoxButtons.OK, MessageBoxIcon.Information)

RestartMSDTCService()

End If

Catch ex As Exception

MessageBox.Show(ex.Message, "Error Writing to Registry", MessageBoxButtons.OK, MessageBoxIcon.Error)

Finally

readRegKey.Close()

writeRegKey.Close()

End Try

End Sub

Private Sub RestartMSDTCService()

Try

Dim serviceController As New System.ServiceProcess.ServiceController("MSDTC")

If serviceController.Status = ServiceProcess.ServiceControllerStatus.Running Then

If serviceController.CanStop Then

serviceController.Stop()

serviceController.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped)

serviceController.Start()

serviceController.WaitForStatus(ServiceProcess.ServiceControllerStatus.Running, System.TimeSpan.FromSeconds(3))

End If

ElseIf serviceController.Status = ServiceProcess.ServiceControllerStatus.Stopped Then

serviceController.Start()

serviceController.WaitForStatus(ServiceProcess.ServiceControllerStatus.Running, System.TimeSpan.FromSeconds(3))

End If

Catch ex As Exception

MessageBox.Show(ex.Message, "Error Restarting MSDTC Service", MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try

End Sub

End Module

CoreyMc at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Transactions Programming...

Software Development for Windows Vista

Site Classified