title: MSDTC on server 'server is unavailable'
body: <p>I get this weird error on SQL Server. And I cannot find solution in older posts. </p>
  
  <p>I have this procedure:</p>
  
  <pre><code>create proc _upJM_SyncAll_test
  as
  begin
      DECLARE @SQLString nvarchar(max)
  
  set @SQLString = N'
  DELETE FROM OPENQUERY([LOCAL_MYSQL],''SELECT acSubject FROM _utjm_setitemprices'') where acSubject not in (select acSubject from _uvJM_SetSubj)
  DELETE FROM OPENQUERY([LOCAL_MYSQL],''SELECT acSubject FROM _utjm_setsubj'') where acSubject not in (select acSubject from _uvJM_SetSubj)
  
  update a
  set acName2 = b.acName2,
      acName3 = b.acName3,
      acAddress = b.acAddress,
      acPost = b.acPost,
      acPostName = b.acPostName, 
      acCountry = b.acCountry, 
      acVATCodePrefix = b.acVATCodePrefix,
      acCode = b.acCode, 
      anDaysForPayment = b.anDaysForPayment
  from OPENQUERY([LOCAL_MYSQL],''SELECT * FROM _utjm_setsubj'') a join _uvJM_SetSubj b on (a.acSubject = b.acSubject)
  where 1=1
  and (   isnull(a.acName2,'''') &lt;&gt; isnull(b.acName2,'''') OR 
          isnull(a.acName3,'''') &lt;&gt; isnull(b.acName3,'''') OR 
          isnull(a.acAddress,'''') &lt;&gt; isnull(b.acAddress,'''') OR 
          isnull(a.acPost,'''') &lt;&gt; isnull(b.acPost,'''') OR 
          isnull(a.acPostName,'''') &lt;&gt; isnull(b.acPostName,'''') OR 
          isnull(a.acCountry,'''') &lt;&gt; isnull(b.acCountry,'''') OR 
          isnull(a.acVATCodePrefix,'''') &lt;&gt; isnull(b.acVATCodePrefix,'''') OR 
          isnull(a.acCode,'''') &lt;&gt; isnull(b.acCode,'''') OR 
          isnull(a.anDaysForPayment,'''') &lt;&gt; isnull(b.anDaysForPayment,'''')
  )
  
  insert into OPENQUERY([LOCAL_MYSQL],''SELECT * FROM _utjm_setsubj'') (acSubject, acName2, acName3, acAddress, acPost, acPostName, acCountry, acVATCodePrefix, acCode, anDaysForPayment)
  select b.acSubject, b.acName2, b.acName3, b.acAddress, b.acPost, b.acPostName, b.acCountry, b.acVATCodePrefix, b.acCode, b.anDaysForPayment
  from OPENQUERY([LOCAL_MYSQL],''SELECT * FROM _utjm_setsubj'') a right join _uvJM_SetSubj b on (a.acSubject = b.acSubject)
  where a.acSubject is null '
  
  EXECUTE sp_executesql @SQLString;
  end
  </code></pre>
  
  <p>When I run procedure in management studio like this:</p>
  
  <pre><code>  exec dbo._upJM_SyncAll_test
  </code></pre>
  
  <p>everything is OK. I get no error, sync is working just fine. </p>
  
  <p>But when I put execute in trigger like this:</p>
  
  <pre><code>create trigger _utrJM_SetSubj on tHE_SetSubj after insert, update, delete
  as
  begin
      exec dbo._upJM_SyncAll_test
  end
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>Msg 8501, Level 16, State 3, Procedure _upJM_SyncAll_test, Line 54<br>
    MSDTC on server 'server' is unavailable.</p>
  </blockquote>
  
  <p>Procedure _upJM_SyncAll_test has only 39 lines... </p>