AJ.
AJ.

Reputation: 345

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?

Upvotes: 4

Views: 2662

Answers (4)

Paulo Moreira
Paulo Moreira

Reputation: 21

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;
}

Upvotes: 2

Jürgen Steinblock
Jürgen Steinblock

Reputation: 31743

If your DBMS is SQL Server 2000 and you use a TransactionScope a distributed transaction is created even for local Transaction. However SQL Server 2005 (and probably SQL Server 2008) are smart enough to figure out that a distributed Transaction is not needed. I don't know if that only applies to local DB's or even is true if you Transaction only involves a single DB even if it's on a remove server. http://davidhayden.com/blog/dave/archive/2005/12/09/2615.aspx

One hint, you can use a batch query to avoid the TransactionScope.

http://subsonicproject.com/docs/BatchQuery

BatchQuery, QueueForTransaction and ExecuteTransaction will not use a TransactionScope (of course that depends on the provider implementation) but choose the transaction mechanismn of the underlying data provider (SqlTransaction in this case) which won't require MSTDC.

Upvotes: 0

user465522
user465522

Reputation: 11

This might be helpful:

http://www.thereforesystems.com/turn-on-msdtc-windows-7/

Upvotes: 1

Randy Levy
Randy Levy

Reputation: 22655

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.

Upvotes: 7

Related Questions