链接服务器无法开始分布式事务 - SQL Server

Posted

技术标签:

【中文标题】链接服务器无法开始分布式事务 - SQL Server【英文标题】:Linked Server unable to begin a distributed transaction - SQL Server 【发布时间】:2019-12-09 20:19:48 【问题描述】:

我是SQL Server 2016 (SP2-CU7-GDR) 的最终用户。

我正在尝试执行以下性质的查询:

DECLARE @sqlcode VARCHAR(MAX)
SET @sqlcode = 'proprietary sql code'
TRUNCATE TABLE [wundermahndb].[dbo].[Training]
INSERT INTO [wundermahndb].[dbo].[Training]
exec ( @sqlcode ) at OLAP

我最终得到的是一个错误:

OLE DB provider "OraOLEDB.Oracle" for linked server "OLAP" returned message "Unable to enlist in the transaction.".
Msg 7391, Level 16, State 2, Line 243
The operation could not be performed because OLE DB provider "OraOLEDB.Oracle" for linked server "OLAP" was unable to begin a distributed transaction.

然后我尝试在查询顶部添加这两行:

set XACT_ABORT on
EXEC master.dbo.sp_serveroption @server=N'OLAP', @optname=N'rpc out', @optvalue=N'true'

并得到以下错误:

Msg 15247, Level 16, State 1, Procedure sp_serveroption, Line 27 [Batch Start Line 0]
User does not have permission to perform this action.
OLE DB provider "OraOLEDB.Oracle" for linked server "OLAP" returned message "Unable to enlist in the transaction.".
Msg 7391, Level 16, State 2, Line 243
The operation could not be performed because OLE DB provider "OraOLEDB.Oracle" for linked server "OLAP" was unable to begin a distributed transaction.

我引用了this post,但该解决方案是我在上面尝试过的,显然不起作用。

我也看过:

Unable to begin a distributed transaction The operation could not be performed because OLE DB provider "SQLNCLI10" for linked server "(null)" was unable to begin a distributed transaction

如何运行此查询?

(注意 - 我使用的是 SSMS 2017)

更新

如果我删除 TRUNCATE TABLE...INSERT INTO...,然后简单地发出:

DECLARE @sqlcode VARCHAR(MAX)
SET @sqlcode = 'proprietary sql code'
exec ( @sqlcode ) at OLAP

它正常运行并返回行。

【问题讨论】:

【参考方案1】:

关闭链接服务器的remote proc transaction promotionoption:

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

因此 SQL Server 不会尝试与远程服务器启动分布式事务。

【讨论】:

Msg 15247, Level 16, State 1, Procedure sp_serveroption, Line 27 [Batch Start Line 0] User does not have permission to perform this action. OLE DB provider "OraOLEDB.Oracle" for linked server "ORAD" returned message "Unable to enlist in the transaction.". Msg 7391, Level 16, State 2, Line 244 The operation could not be performed because OLE DB provider "OraOLEDB.Oracle" for linked server "ORAD" was unable to begin a distributed transaction. 假设我没有适当的权限这样做?

以上是关于链接服务器无法开始分布式事务 - SQL Server的主要内容,如果未能解决你的问题,请参考以下文章

无法执行操作,因为链接服务器的 OLE DB 提供程序“SQLNCLI11”无法开始分布式事务

消息 7391:链接服务器无法开始分布式事务(两个 svrs 在本地运行)

在没有分布式事务的链接服务器上调用过程

sql server 和 mysql 之间的链接服务器上的分布式事务

无法执行该操作,因为链接服务器 "xxxxx" 的 OLE DB 访问接口 "SQLNCLI" 无法启动分布式事务

无法执行该操作,因为链接服务器 "XXX" 的 OLE DB 访问接口 "SQLNCLI10" 无法启动分布式事务。