简体   繁体   中英

Openquery procedure from linked server

I'm calling procedure from server B:

select * from openquery(A,'exec sp_qa2')

sp_qa2 in Server A is this:

use master
go
create procedure sp_qa2
begin
declare @sql nvarchar(1000)
SET @sql = 'USE [?];  EXEC    [dbo].[sp_qa1]'
EXEC sp_MSforeachdb @sql
end

and sp_qa1 in Server A is this:

create procedure sp_qa1
begin
declare @a int
end

This error is returning:

Msg 208, Level 16, State 1, Procedure sp_MSforeach_worker, Line 102 [Batch Start Line 2] Invalid object name '#qtemp'.

How can I fix this?

Is your RPC and RPC OUT option of your Linked server is TRUE ?

Also, you can directly execute the code without openquery like below:

EXEC [A].[database].[schema].sp_qa2

您也可以尝试使用:

EXEC(@sql) AT [RemoteServer]

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