Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How To Find Default Database Alias??

174 views
Skip to first unread message

Mr. K.V.B.L.

unread,
Sep 4, 2008, 4:08:36 PM9/4/08
to
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?

Karl Hanson

unread,
Sep 4, 2008, 11:07:12 PM9/4/08
to

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

walker.l2

unread,
Sep 5, 2008, 5:08:57 AM9/5/08
to
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).

CRPence

unread,
Sep 5, 2008, 10:33:39 PM9/5/08
to

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/software/db2/clifaq.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/infocenter/iseries/v5r4/topic/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

Kent Milligan

unread,
Sep 9, 2008, 2:40:48 PM9/9/08
to
I'm not aware of any. This query would retrieve it:
SELECT CURRENT DATABASE FROM sysibm.sysdummy1

--
Kent Milligan
ISV Enablement - System i
km...@us.eye-bee-m.com (spam trick) GO HAWKEYES!!
>>> ibm.com/iseries/db2
(opinions stated are not necessarily those of my employer)

0 new messages