How To Find Default Database Alias?? - IBM AS400

This is a discussion on How To Find Default Database Alias?? - IBM AS400 ; I have a program that is using SQL CLI and if I dump this program from one machine to another it will need to know the default database name/ alias defined for that machine. Is there an API or something ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: How To Find Default Database Alias??

  1. How To Find Default Database Alias??

    I have a program that is using SQL CLI and if I dump this program from
    one machine to another it will need to know the default database name/
    alias defined for that machine. Is there an API or something I can
    use to get this?

  2. Re: How To Find Default Database Alias??

    Mr. K.V.B.L. wrote:
    > I have a program that is using SQL CLI and if I dump this program from
    > one machine to another it will need to know the default database name/
    > alias defined for that machine. Is there an API or something I can
    > use to get this?


    There may be an API or easier method, but if you want the local RDB name
    as seen via WRKRDBDIRE CL command, a small CL program may work. Using
    DSPRDBDIRE to a temporary outfile, the RCVF command can read each record
    until one with a remote location of *LOCAL is found. The snippet below
    shows the general idea - instead of sending a message with the RDB name,
    a CL module/program could be built with an output parameter to return
    the RDB name to the caller. HTH.

    DCL &LCLRDB *CHAR 18 VALUE(' ')
    DCL &MSG *CHAR 100
    DCLF FILE(QSYS/QADSPDE)

    DSPRDBDIRE OUTPUT(*OUTFILE) OUTFILE(QTEMP/RDBS)
    OVRDBF QADSPDE TOFILE(QTEMP/RDBS)
    READ: RCVF /* Read next RDB record */
    MONMSG CPF0864 EXEC(DO)
    CHGVAR &MSG ('Local RDB not found.')
    SNDPGMMSG MSGID(CPF9897) MSGF(QCPFMSG) MSGDTA(&msg) +
    TOPGMQ(*PRV) MSGTYPE(*INFO)
    ENDDO
    IF (&RWRLOC = '*LOCAL') THEN(DO)
    CHGVAR &LCLRDB &RWRDB
    GOTO GOTIT
    ENDDO
    GOTO READ
    GOTIT: CHGVAR &MSG ('Local RDB name: '||&LCLRDB)
    SNDPGMMSG MSGID(CPF9897) MSGF(QCPFMSG) MSGDTA(&msg) +
    TOPGMQ(*PRV) MSGTYPE(*INFO)

    --
    Karl Hanson

  3. Re: How To Find Default Database Alias??

    Usually the default database name matches the server name. The server
    name can be retrieved via DSPNETA or the QWCRNETA API.

    If your program is only going to be run against a local database, most
    access methods (not sure about SQL CLI) provide a special name (such
    as *LOCAL or LOOPBACK or LOCALHOST) to allow you to do this without
    knowing the database name. If your program can do that, it shouldn't
    need to be changed if you move it to another machine (to run against
    the local database on the new machine).

  4. Re: How To Find Default Database Alias??

    Mr. K.V.B.L. wrote:
    > I have a program that is using SQL CLI and if I dump this program
    > from one machine to another it will need to know the default database
    > name/ alias defined for that machine. Is there an API or something I
    > can use to get this?


    In the SQLCLI program use on the SQLConnect(), the value "*LOCAL" for
    the server name, or I believe even NULL or empty string as server name
    is available to be passed as well, to establish a connection to the
    local database [in the partition or the iASP, where the program is being
    run].

    The NULL for the RDB name on the SQLConnect is noted as possible in
    text for "Restrictions when running server mode" in the following FAQ topic:
    http://www.ibm.com/systems/i/softwar....html#header_3

    The documentation for SQLConnect suggests that if a value is not
    specified [but does not clarify NULL vs empty-string] for the szDSN as
    target database name, that the local database will be used:
    http://publib.boulder.ibm.com/infoce.../cli/rzadp.pdf

    Note that the DSPRDBDIRE mentioned by Karl may be easily replaced
    with a more direct access of the active RDB data, via one of either
    QADBXRDBD or QADBXRMTNM files in QSYS. IIRC the former was granted
    additional public authority, such that in some old release it was
    available only with the *ALLOBJ special authority.

    Regards, Chuck

  5. Re: How To Find Default Database Alias??

    I'm not aware of any. This query would retrieve it:
    SELECT CURRENT DATABASE FROM sysibm.sysdummy1

    Mr. K.V.B.L. wrote:
    > I have a program that is using SQL CLI and if I dump this program from
    > one machine to another it will need to know the default database name/
    > alias defined for that machine. Is there an API or something I can
    > use to get this?


    --
    Kent Milligan
    ISV Enablement - System i
    kmill@us.eye-bee-m.com (spam trick) GO HAWKEYES!!
    >>> ibm.com/iseries/db2

    (opinions stated are not necessarily those of my employer)

+ Reply to Thread