Results 1 to 8 of 8

Thread: MSSQL using UDF across servers

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    MSSQL using UDF across servers

    Hey all,
    I am running into an issue trying to call a user defined function across servers. Then error I am getting is The multi-part identifier "myserver.database.schema.functionname" could not be bound.

    This is the code I am trying to use:

    Code:
    				  declare @storeNo INT
    				  declare @vendorID INT
    				  declare @payAgreed BIT
    				  select @sql = N'select @store = IST.Store_No, @vendor = IVS.Vendor_ID
    								 FROM POHeader H
                                        inner join ' + @DBString + '[Store] IST on H.BusinessUnit = IST.BusinessUnit_ID
                                        inner join ' + @DBString + '[Vendor] IVS on IVS.Store_No = IST.Store_No'
    				  exec sp_executesql @sql 
                                , N'@store INT OUTPUT,@vendor int OUTPUT'
                                ,  @store = @storeNO OUTPUT, @vendor = @vendorID OUTPUT
    
    				  select @sql = N'SET @payAgreedCost = ' + @DBString + '[fn_IsPayByAgreedCostStoreVendor(@storeNo, @vendorID, getdate())]'
    				  exec sp_executesql @sql 
                                , N'@payAgreedCost BIT OUTPUT'
                                , @payAgreedCost = @payAgreed OUTPUT
    any ideas on how to work around this?

    Thanks!

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: MSSQL using UDF across servers

    you need to have linked servers on, and the initiating server needs to know about the destination server. Once you have that set up, you should be able to access the function using: linkservername.databasename.dbo.functionname

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: MSSQL using UDF across servers

    The joins work fine across servers, do those not require linked server being turned on?

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: MSSQL using UDF across servers

    then there's something missing from the multi identifier that isn't right. I know that in the past, I've had to use dbo. even when using UDFs from inside the same db.

    So the question is, what is "@DBString" at the moment the call is made?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: MSSQL using UDF across servers

    yeah the error message contains the full path

    ServerName.DBName.dbo.Functionname

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: MSSQL using UDF across servers

    I moved the ] to the end of the function name and now I get a new error message:
    Invalid column name 'servername'

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: MSSQL using UDF across servers

    I didn't even see that initially... try taking the [ and ] off completely.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: MSSQL using UDF across servers

    yeah that gives the same error... I have been asking around and did some poking around, everything points to wrapping a sp around the function then calling the sp. Gonna try that in the morning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width