Exec SP on Linked server and put that in temp table

后端 未结 2 838
温柔的废话
温柔的废话 2021-02-15 15:24

Need some help on the below issue:

Case 1 : stored procedure is on server 1 - call is from server1

declare @tempCountry table (countryna         


        
2条回答
  •  灰色年华
    2021-02-15 16:05

    You have (I believe) two options here:

    1. To try to avoid the usage of MSDTC (and all these not pleasant things related to Distributed Transactions) by using OPENQUERY rowset function

      /assume (here and below) that [database2_server2] is the name of the linked server/

      declare @tempCountry table (countryname char(50)) insert into @tempCountry select * from openquery([database2_server2], '[database1_server1].[dbo].[getcountrylist]') select * from @tempCountry

    OR

    1. You can set the linked server's option Enable Promotion Of Distributed Transaction to False in order to prevent the local transaction to promote the distributed transaction and therefore use of MSDTC:

      EXEC master.dbo.sp_serveroption @server = N'database2_server2', @optname = N'remote proc transaction promotion', @optvalue = N'false'

      and your original query should work fine:

      declare @tempCountry table (countryname char(50)) insert into @tempCountry exec [database2_server2].[database1_server1].[dbo].[getcountrylist] select * from @tempCountry

      Enable Promotion Of Distributed Transaction=False

提交回复
热议问题