在以下问题上需要一些帮助:

情况1 :存储过程在服务器1上-调用来自server1

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

结果:成功执行

Case2 :i如果正在使用链接服务器从不同的服务器调用相同的存储过程,例如:
declare @tempCountry table (countryname char(50))
insert into @tempCountry
    exec [database2_server2].[database1_server1].[dbo].[getcountrylist]
Select * from @tempCountry

结果



案例3

但是,当尝试单独执行存储过程[不插入临时表]时,如下所示
exec [database2_server2].[database1_server1].[dbo].[getcountrylist]

结果:正在执行存储过程而没有任何错误并返回数据。

我忘了提到正在使用SQL Server2005。根据服务器管理员的说法,您建议我使用的功能在2005年不可用。

最佳答案

我相信您有两种选择:

  • 通过使用these行集函数来尝试避免使用MSDTC(以及与分布式事务相关的所有OPENQUERY不愉快的事情)

    /假定(此处和下方)[database2_server2]是链接服务器的名称/
    declare @tempCountry table (countryname char(50))insert into @tempCountryselect * from openquery([database2_server2], '[database1_server1].[dbo].[getcountrylist]')select * from @tempCountry


  • 可以将链接服务器的选项Enable Promotion Of Distributed Transaction设置为False,以防止本地事务提升分布式事务,从而避免使用MSDTC:
    EXEC master.dbo.sp_serveroption @server = N'database2_server2', @optname = N'remote proc transaction promotion', @optvalue = N'false'
    并且您的原始查询应该可以正常工作:
    declare @tempCountry table (countryname char(50))insert into @tempCountry exec [database2_server2].[database1_server1].[dbo].[getcountrylist]select * from @tempCountry
  • 关于sql-server - 链接服务器上的Exec SP并将其放在临时表中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27726567/

    10-11 06:43
    查看更多