更新时间:2023-02-03 18:38:44
尝试指定存储过程的数据库和模式名称:选择 * from OPENQUERY (linkserver,' Exec YOURDB.dbo.testsp')
解决方法 - 使用结果集将SP包装到新SP:ALTER PROCEDURE testsp2
AS
EXEC testsp
WITH RESULT SETS
(
(
FirstName nvarchar (max),
LastName nvarchar (max),
EmailAddress1 nvarchar (max)
)
);
Sample Sp
create procedure testsp
as
DECLARE @idoc int,@doc varchar(1000)=
'<OutLookContact>
<Contact FirstName="Asif" LastName="Ghafoor" EmailAddress1="asifghafoor@my.web.pk" />
<Contact FirstName="Rameez" LastName="Ali" EmailAddress1="rameezali@my.web.pk" />
</OutLookContact>'
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
SELECT * FROM OPENXML (@idoc, '/OutLookContact/Contact',1)
WITH (FirstName varchar(50),LastName varchar(50),EmailAddress1 varchar(50))
Now when executing
select * from OPENQUERY ( linkserver,'Exec testsp' )
But it returns error Error Message: Msg 11529, Level 16, State 1, Procedure sp_describe_first_result_set, Line 1 The metadata could not be determined because every code path results in an error; see previous errors for some of these. Msg 2812, Level 16, State 62, Procedure sp_describe_first_result_set, Line 1 Could not find stored procedure 'testsp'.
Try specifying the database and schema name for your stored procedure:select * from OPENQUERY ( linkserver, 'Exec YOURDB.dbo.testsp' )
Workaround - wrap SP to new SP with result set:ALTER PROCEDURE testsp2 AS EXEC testsp WITH RESULT SETS ( ( FirstName nvarchar(max), LastName nvarchar(max), EmailAddress1 nvarchar(max) ) );