Re: C++, SQLCLI: Making a remote DB2 connection

Kelly Beard <[email protected]>
Newsgroups gmane.comp.lang.as400.c
Message-ID <CAOvM2St6U8i23aH_PpAK9y8EOGYTyQ4frf-g3qC_Sa0QtNsACQ@mail.gmail.com>
After I sent this email I found some of my answers (that always seems to
happen).  :-)

Do a WRKRDBDIRE and add an entry that has the db name and host particulars
to point to the right system.  If you're using STRSQL for testing, then you
do a "CONNECT TO DBNAME USER <user> USING '<password>'"

If in code, create your db connection handle then connect using:
    sqlRet = SQLConnect(cv_hSqlDbc, databaseName, SQL_NTS, user, SQL_NTS,
password, SQL_NTS);

I'm setting a default library with my connection (I'm doing this after the
connect; doesn't seem to be a problem)
    sqlRet = SQLSetConnectAttr(cv_hSqlDbc, SQL_ATTR_DBC_DEFAULT_LIB,
(SQLPOINTER)library.c_str(), (SQLINTEGER)library.length());

According to the docs, in order for this to work, you have to set system
naming off (do this step before the above SetConnectAttr()).
    SQLINTEGER sysnaming = SQL_FALSE;
    SQLPOINTER option;
    option = &sysnaming;
    sqlRet = SQLSetConnectOption(cv_hSqlDbc, SQL_ATTR_DBC_SYS_NAMING,
option);

This seems to work ok, if I have two connections and then 'ask' what their
default library is, the two report back the correct answers (the default
library is different for each connection).

    char buf[100];
    long olen;
    SQLGetConnectAttr(local_db.getConnectionHandle(),
SQL_ATTR_DBC_DEFAULT_LIB, (SQLPOINTER)buf, 100, &olen);
    cout << "local lib=" << buf << endl;
    SQLGetConnectAttr(remote_db.getConnectionHandle(),
SQL_ATTR_DBC_DEFAULT_LIB, (SQLPOINTER)buf, 100, &olen);
    cout << "remote lib=" << buf << endl;

local lib=BOBV
remote lib=DF99328

BUT (with IBM, C++, etc there always seems to be a 'but') - if I do an
unqualified SELECT on a couple of tables, one of the connections is using
the default database of the other connection.  I'm trying to figure this out

    SQLSelectExecute(local_db, "SELECT * FROM DRIVERS_SNAPSHOT", rows);

    SQLSelectExecute(remote_db, "SELECT * FROM UNITS_SNAPSHOT", rows);

In this instance, UNITS_SNAPSHOT is on a remote system and I've set the
default library for it to be DF99328, but the connection information is
trying to use BOBV.

SQLSelectExecute.cpp(67): sqlRet=-1 NativeError=-204 SqlState=42704
Message=UNITS_SNAPSHOT in BOBV type *FILE not found.

This connection should effectively be saying SELECT * FROM
DF99328.UNITS_SNAPSHOT

That's the only thing I need to figure out.

-- 
Kelly Beard
-- 
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list
To post a message email: C400-L-Zwy7GipZuJhWk0Htik3J/[email protected]
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request-Zwy7GipZuJhWk0Htik3J/[email protected]
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.