在 OpenQuery 中调用参数化存储过程 - SQL Server 2008
我正在 OpenQuery 中调用存储过程并将参数传递给存储过程。
declare @Src nvarchar(max),@Tgt nvarchar(max)
declare @sql_str nvarchar (4000)
set @Src = '$\VMT\Versions\0900\AMS\'
set @Tgt = '$\VMT\Versions\0900\Base\'
set @sql_str = 'exec [Tfs_VMT Collection].dbo.MergeCandidate ''' + @Src+ ''' , ''' +@Tgt+''' '
set @sql_str = 'select * into #test from openquery(ODSSERVER,''' +Replace(@sql_str,'''', '''''') +''')'
print @sql_str
EXEC (@sql_str)
但这失败并出现以下错误
消息 7357,16 级,状态 2,第 1 行
无法处理对象“exec [Tfs_VMT 集合].dbo.MergeCandidate '$\VMT\Versions\0900\AMS\' , '$\VMT\Versions\0900\Base\' ”。OLE DB 提供程序“SQLNCLI10” 链接服务器“ODSSERVER”表示该对象没有 列或当前用户没有该对象的权限。
我检查过这与权限无关。
你能帮忙吗?
I am calling a stored procedure in OpenQuery
and passing parameters to the stored procedure.
declare @Src nvarchar(max),@Tgt nvarchar(max)
declare @sql_str nvarchar (4000)
set @Src = '$\VMT\Versions\0900\AMS\'
set @Tgt = '$\VMT\Versions\0900\Base\'
set @sql_str = 'exec [Tfs_VMT Collection].dbo.MergeCandidate ''' + @Src+ ''' , ''' +@Tgt+''' '
set @sql_str = 'select * into #test from openquery(ODSSERVER,''' +Replace(@sql_str,'''', '''''') +''')'
print @sql_str
EXEC (@sql_str)
but this fails with following error
Msg 7357, Level 16, State 2, Line 1
Cannot process the object "exec [Tfs_VMT
Collection].dbo.MergeCandidate '$\VMT\Versions\0900\AMS\' ,
'$\VMT\Versions\0900\Base\' ". The OLE DB provider "SQLNCLI10" for
linked server "ODSSERVER" indicates that either the object has no
columns or the current user does not have permissions on that object.
I have checked this has nothing to do with permissions.
Can you please help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试从 openquery 查询中删除 exec。您应该能够只传递过程名称/参数。
Try removing the exec from your openquery query. You should be able to just pass in the procedure name/parameters.