Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding MSDTC in Windows

To use transaction construct(as follows) in Subsonic, MSDTC needs to be running on Windows machine. Right?

        using (TransactionScope ts = new TransactionScope())
        {
            using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
            {
                // update table 1
                // update table 2

                // ts.commit here

            }
        }
  1. Is MS-DTC a default service on Windows systems(XP, Vista, Windows 7, Servers etc)?
  2. If it is not enabled, how can I make sure it gets enabled during the installation process of my application?
like image 432
AJ. Avatar asked Dec 30 '22 10:12

AJ.


2 Answers

MSDTC should come installed with windows. If it's not it can be installed with the following command:

msdtc -install

You can configure the MSDTC service using sc.exe. Set the service to start automatically and start the service:

sc config msdtc start= auto
sc start msdtc

Note you will need administrator privilege to perform the above.

like image 114
Randy supports Monica Avatar answered Jan 11 '23 08:01

Randy supports Monica


I use:

private bool InitMsdtc()
{
    System.ServiceProcess.ServiceController control = new System.ServiceProcess.ServiceController("MSDTC");
    if (control.Status == System.ServiceProcess.ServiceControllerStatus.Stopped)
        control.Start();
    else if (control.Status == System.ServiceProcess.ServiceControllerStatus.Paused)
        control.Continue();
    return true;
}
like image 34
Paulo Moreira Avatar answered Jan 11 '23 07:01

Paulo Moreira