简体   繁体   中英

Linked Server unable to begin a distributed transaction - SQL Server

I am end user on SQL Server 2016 (SP2-CU7-GDR) .

I am trying to execute a query of the following nature:

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

What I end up with is an error for:

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.

I then tried adding these two lines at the top of my query:

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

And got the following error:

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.

I have referenced this post but that solution is what I have tried above which is clearly not working.

I have also looked:

How can I run this query?

(NOTE - I am using SSMS 2017)

UPDATE

If I remove TRUNCATE TABLE... and INSERT INTO... , and simply issue:

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

It runs normally and returns the rows.

Turn off remote proc transaction promotion option for the linked server:

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

So SQL Server doesn't attempt to start a distributed transaction with the remote server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM