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]
I actually discovered what I needed was to modify the registry. Here is the code I used. Hope someone finds it useful.
Imports
Microsoft.win32Module
SampleModuleFriend 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 = FalseTryDim networkDtcAccess As Integer = readRegKey.GetValue("NetworkDtcAccess", 0)If networkDtcAccess = 0 ThenwriteRegKey.SetValue(
"NetworkDtcAccess", 1)changedItem =
TrueEnd IfDim networkDtcAccessOutbound As Integer = readRegKey.GetValue("NetworkDtcAccessOutbound", 0)If networkDtcAccessOutbound = 0 ThenwriteRegKey.SetValue(
"NetworkDtcAccessOutbound", 1)changedItem =
TrueEnd IfDim networkDtcAccessTransactions As Integer = readRegKey.GetValue("NetworkDtcAccessTransactions", 0)If networkDtcAccessTransactions = 0 ThenwriteRegKey.SetValue(
"NetworkDtcAccessTransactions", 1)changedItem =
TrueEnd IfIf changedItem = True ThenMessageBox.Show(
"ToolName must update you system MSDTC settings. Please wait.", "MSDTC Update", MessageBoxButtons.OK, MessageBoxIcon.Information)RestartMSDTCService()
End IfCatch ex As ExceptionMessageBox.Show(ex.Message,
"Error Writing to Registry", MessageBoxButtons.OK, MessageBoxIcon.Error)FinallyreadRegKey.Close()
writeRegKey.Close()
End TryEnd SubPrivate Sub RestartMSDTCService()TryDim serviceController As New System.ServiceProcess.ServiceController("MSDTC")If serviceController.Status = ServiceProcess.ServiceControllerStatus.Running ThenIf serviceController.CanStop ThenserviceController.Stop()
serviceController.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped)
serviceController.Start()
serviceController.WaitForStatus(ServiceProcess.ServiceControllerStatus.Running, System.TimeSpan.FromSeconds(3))
End IfElseIf serviceController.Status = ServiceProcess.ServiceControllerStatus.Stopped ThenserviceController.Start()
serviceController.WaitForStatus(ServiceProcess.ServiceControllerStatus.Running, System.TimeSpan.FromSeconds(3))
End IfCatch ex As ExceptionMessageBox.Show(ex.Message,
"Error Restarting MSDTC Service", MessageBoxButtons.OK, MessageBoxIcon.Error)End TryEnd SubEnd
Module