Home Forums Programming General Call DB2 stored procedure using Linked Server? RE: Call DB2 stored procedure using Linked Server?

  • 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)