Inserting Results Of Stored Procedure From Linked Server

跟風遠走 提交于 2019-12-10 13:12:24

问题


Is it possible to insert the results of a remote stored procedure into a temp table? For example

CREATE TABLE #test(id INT)
INSERT INTO #test 
EXEC [linkedserver].remoteDB.dbo.tst
DROP TABLE #test

Where tst is a stored procedure that returns IDs.

If I run the exec on its own it works fine

EXEC [linkedserver].remoteDB.dbo.tst

However when I put it as part of an insert I get this error

"OLE DB provider "SQLNCLI" for linked server "linkedserver" returned message "The partner transaction manager has disabled its support for remote/network transactions.". Msg 7391, Level 16, State 2, Line 2 The operation could not be performed because OLE DB provider "SQLNCLI" for linked server "linkedserver" was unable to begin a distributed transaction."

One machine is running SQL Server 2005 and the other 2008, both are running the "Distributed Transaction Coordinator" service.


回答1:


It sounds to me like the support for remote transactions has not been properly enabled.

Have you tried following the instructions here:

  • The partner transaction manager has disabled its support for remote/network transactions



回答2:


I think the reason is when we call EXEC alone it's not called within a transaction, so no problem. When we call INSERT EXEC, it's called within a txn, so the remote server has to enable network txn support. But we can avoid doing that with this:

https://dba.stackexchange.com/questions/46541/how-to-insert-in-table-from-remote-stored-procedure-without-creating-a-distribut



来源:https://stackoverflow.com/questions/6874697/inserting-results-of-stored-procedure-from-linked-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!