Call DB2 stored procedure using Linked Server?

  • Hi Everyone,

    Is it possible to call a DB2 stored procedure using a linked server? I've read a bunch of conflicting information out on the internet. Various posts have claimed it is not supported but then I came across a couple of posts which suggest it is possible. If it is possible..please provide me with a link to the information. Any help is appreciated!

    Thanks

  • Have you tried using the EXEC..AT feature?

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • I know it's an old post but the following should help a lot.

    http://www.mcpressonline.com/index2.php?option=com_content&do_pdf=1&id=1541

    The keys to the magic appear in the following...

    --

    -- Create Linked Server using ODBC DSN "AS400"

    --

    sp_addlinkedserver

    @server=N'DB2400',

    @srvproduct=N'DB2 UDB for iSeries',

    @provider=N'MSDASQL',

    @datasrc=N'AS400',

    @provstr='CMT=0;SYSTEM=as400.mycompany.com',

    @catalog='S104X824'

    go

    --

    -- Define the credentials that will be used to

    -- access objects hosted by the Linked Server

    --

    sp_addlinkedsrvlogin @rmtsrvname=N'DB2400',

    @useself='false',

    @rmtuser=N'MyUser',

    @rmtpassword='MyPassword'

    go

    --

    -- RPC option is required for doing EXEC AT

    --

    EXEC sp_serveroption 'DB2400', 'rpc out', true

    go

    The biggest key here is that you must use the MSDASQL driver and you must enable "rpc out".

    The article at the link also gives an example call to return a result set as follows... Obviously, the temp table must already exist but that's also covered in the article.

    --

    -- A DB2 stored procedure can be executed

    --

    Set @OrderID = 10249

    Insert Into #tmpOrderHdr

    Exec ('Call DATALIB.GetOrders (?)', @OrderID) AT DB2400

    [font="Arial Black"]To be clear, I've not tried any of this, yet. Our infrastructure team is in the process of installing the correct MSDASQL driver.[/font]

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Sweet. Really nice find, Jeff. This goes in my Favorites list... 🙂

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • I am newbie to linked server concept, I am looking for help to resolve my issue. Please suggest.

    My requirement:

    In DB2 data base I have a stored procedure and from SQL 2008 R2 using Linked server I need to be able to execute stored procedure. I am getting the error while I am trying to execute.

    Created SP as below with db2admin user:

    CREATE OR REPLACE PROCEDURE SP_MyStoredProcedure

    LANGUAGE SQL

    SPECIFIC SP_MyStoredProcedure

    -- EXTERNAL ACTION

    BEGIN

    .......

    END

    select * from [MyDb2LinkedServer].[db2DB].[db2admin].TLS_MyDb2Table and I get the results, which means my linked server DB2 connectivity is fine.

    Then while executing as below SP got the error

    exec [MyDb2LinkedServer].[db2DB].[db2admin].SP_MyStoredProcedure

    Error:

    OLE DB provider "DB2OLEDB" for linked server "MyDb2LinkedServer" returned message "Routine "*rocedure"?SQL150518145704050?...erver"."SP_MyStoredProcedure"?*?4" (specific name "") is implemented with code in library or path "", function "" which cannot be accessed. Reason code: "". SQLSTATE: 42724, SQLCODE: -444".

    Msg 7212, Level 17, State 1, Line 1

    Could not execute procedure 'SP_MyStoredProcedure' on remote server 'MyDb2LinkedServer'.

    Here in the error

    specific name ""

    library or path ""

    function ""

    Reason code: ""

    all are empty, no much information is available.

    Need help on this and how this can be resolved? Any help is appreciated.

    Note:

    "rpc", "rpc out" both options are true.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply