需要有关以下问题的一些帮助:
Case 1:存储过程位于服务器 1 上 - 调用来自服务器 1
declare @tempCountry table (countryname char(50))
insert into @tempCountry
exec [database1_server1].[dbo].[getcountrylist]
Select * from @tempCountry
结果:执行成功
Case2:如果使用链接服务器从不同的服务器调用相同的存储过程,如下所示:
declare @tempCountry table (countryname char(50))
insert into @tempCountry
exec [database2_server2].[database1_server1].[dbo].[getcountrylist]
Select * from @tempCountry
Result
消息 7391,级别 16,状态 2,第 2 行
无法执行该操作,因为链接服务器“Server2_Database2”的 OLEDB 提供程序“SQLNCLI”无法开始分布式事务。
Case 3
但是当尝试单独执行存储过程[不插入临时表]时,如下所示
exec [database2_server2].[database1_server1].[dbo].[getcountrylist]
结果:即执行存储过程,没有任何错误并返回数据。
我忘了提及我正在使用 SQL Server 2005。根据服务器管理员的说法,您建议我使用的功能在 2005 中不可用。
你(我相信)这里有两个选择:
-
尽量避免使用MSDTC
(和所有these http://blogs.msdn.com/b/sqlforum/archive/2010/12/20/faq-how-do-i-configure-sql-server-to-enable-distributed-transactions-via-linked-server.aspx与分布式事务相关的不愉快的事情)通过使用开放查询 http://msdn.microsoft.com/en-us/library/ms188427.aspx行集函数
/假设(此处和下文)[database2_server2] 是链接服务器的名称/
declare @tempCountry table (countryname char(50))
insert into @tempCountry
select * from openquery([database2_server2], '[database1_server1].[dbo].[getcountrylist]')
select * from @tempCountry
OR
-
您可以设置链接服务器的选项Enable Promotion Of Distributed Transaction
to 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)