2015-09-16 50 views
1

下面的查询在SQL Server中工作的罚款2008 R2SQL Server的OPENQUERY来执行命令

select * 
from openquery(LinkedServerName, 'exec databaseName.dbo.SP_GET_INFO'); 

我尝试使用exec命令将其转换,但没有运气。

例如:

exec ('call databaseName.dbo.SP_GET_INFO') at LinkedServerName 

始终得到这个消息的语法错误:

Could not execute statement on remote server 'LinkedServerName'

感谢。

+1

LinkedServerName处的exec('exec databaseName.dbo.SP_GET_INFO') – lad2025

+0

谢谢@ lad2025,但是我得到这个错误: 链接服务器的OLE DB提供程序“STREAM”“(null)”返回消息“The操作多步OL​​E DB生成的错误如果可用,检查OLE DB的状态值,没有工作完成。“ – iperezmel78

+0

您的存储过程是否返回XML/TEXT/Image等? – lad2025

回答

0

感谢@ lad2025的帮助。

使用下面的脚本将工作:

exec ('databaseName.dbo.SP_GET_INFO') at LinkedServerName 

我第一次测试,它并没有因为我用来创建链接服务器的驱动程序的工作的代码。 我已经使用了“Microsoft OLE DB Provider for ODBC Drivers”。有了这一个我得到了错误:

OLE DB provider "STREAM" for linked server "(null)" returned message ...

的原因是因为在存储过程中我做了选择在具有空值的ntext列。

因此,我将驱动程序更改为“用于SQL Server的Microsoft OLE DB提供程序”,该脚本正常工作。

希望这可以帮助别人。