Do you support MSDTC service?

Programming, error messages and sample code > ASP.NET

What is MSDTC

MSDTC, Microsoft Distributed Transaction Coordinator, is essentially, as name suggests, a coordinator/manager to handle transactions that are distributed over multiple machines. Let’s say we start a transaction, where one of the steps includes querying data from a different Sql Server instance on a different physical machine; MSDTC comes into action with these specific tasks that need transaction coordination across different physical machines. It executes the section of code that is supposed to run on remote machines and brings back the results to local Sql instance. In this process, if any issue were to occur, on the remote machine that results in rollback, MSDTC makes sure the original transaction on this machine also rolls-back safely.
 

Do you support MSDTC

Yes, msdtc is supported in our semi plans.
 

How to use MSDTC

Below is a demo to test MSDTC:
 
test.aspx
<% @Page Language="C#" %>
<% @Import Namespace="System.Transactions" %>
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<% @Import Namespace="System.Text" %>

<script runat="server">
   protected void Page_Load(object sender, EventArgs ea)
   {
            using (TransactionScope scope = new TransactionScope())
       {
                  SqlConnection conn = new SqlConnection("data source=xx;uid=xx;password=xx;database=xx");
                  conn.Open();
                  SqlCommand cmd = new SqlCommand();
                  cmd.Connection = conn;
                  cmd.CommandText = "update ActivityLog set IpAddress='1.1.1.2' where Id = 1";
                  cmd.ExecuteNonQuery();
                  
                  SqlConnection conn2 = new SqlConnection("data source=xx;uid=xx;password=xx;database=xx");
                  conn2.Open();
                  SqlCommand cmd2 = new SqlCommand();
                  cmd2.Connection = conn2;
                  cmd2.CommandText = "update Address set Email='[email protected]' where Id = 1";
                  cmd2.ExecuteNonQuery();
                  scope.Complete();
            }            
   }

</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
   <title></title>
</head>
<body>
   <form id="form1" runat="server">
   <div>
   
   </div>
   </form>
</body>
</html>
 
web.config:
<configuration>
  <system.web>
     <compilation>
        <assemblies>
     <add assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        </assemblies>
     </compilation>
  </system.web>
</configuration>