Remote table-Valued Function Calls are not allowed

こ雲淡風輕ζ 提交于 2019-12-10 00:38:16

问题


How can I make this work?Im running a table valued function from a remote linked server. i tried adding no lock to this 4 part naming but still i get the same error. Im using mssql-2008

select * from [110.10.10.100].testdbname.dbo.ufn_getdata('4/25/2013') as tb;(NOLOCK)

回答1:


You need to add WITH (NOLOCK). Not entirely sure why but I just ran into this issue today and this solved my issue.

SELECT * 
FROM [110.10.10.100].testdbname.dbo.ufn_getdata('4/25/2013') AS tb WITH (NOLOCK);



回答2:


Nolock doesn't work for me.
However, using OPENQUERY does...

Replace DMS_DB.dbo.tfu_V_DMS_Desktop(''de'')' with [110.10.10.100].testdbname.dbo.ufn_getdata(''4/25/2013'')

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tfu_V_DMS_Desktop]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[tfu_V_DMS_Desktop]
GO



CREATE FUNCTION [dbo].[tfu_V_DMS_Desktop] 
(   
    @param1 int 
)
    RETURNS table 
AS
RETURN 
(
    -- Add the SELECT statement with parameter references here
    -- SELECT 0 as abc
    SELECT * FROM OPENQUERY(CORDB2008R2, 'SELECT * FROM DMS_DB.dbo.tfu_V_DMS_Desktop(''de'')') 
)

GO

On a footnote, the problem is OPENQUERY doesn't allow a variable, so you cannot have variable parameters. You can however reference all tables and views as views from a remote server, and just create the table-valued function 1:1 locally. This will probably be slow, however.




回答3:


Also make sure that RPC OUT is set to TRUE in linked server options. This option also needed when you try to execute stored procedure on linked server. Otherwise you will get following error.

Server 'servername' is not configured for RPC




回答4:


Following SQL OpenQuery command should be working

Parameter values which are surrounded with ' are replaced with double ''

So in this case there is no need to create a stored procedure on the target instance database

SELECT * 
FROM OPENQUERY(
    [110.10.10.100],
    'SELECT * FROM testdbname.dbo.ufn_getdata(''4/25/2013'')'
) as oq



回答5:


This is the example of calling a remote SQL user defined function returning a table as output in SQL Server 2014. It is working for me.

Declare @Param1 Varchar(10)
Declare @SqlText nvarchar(4000)
Set  @Param1 = 'xxx'
Set @SqlText = 'SELECT * FROM Database.dbo.ufn_Function (''' + @Param1 + ''')'
EXEC LinkedServer.Database.dbo.sp_executesql @SqlText



回答6:


See this answer:

Use OPENQUERY

Replace SP call with SELECT ... FROM fn() query and it should work.



来源:https://stackoverflow.com/questions/16209135/remote-table-valued-function-calls-are-not-allowed

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