By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,610 Members | 1,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,610 IT Pros & Developers. It's quick & easy.

How to connect to the DB2 on a REMOTE machine from a C++ application on Linux?

P: n/a
mjf
I'd like to connect from any Linux machine to the DB2 on a Linux server
via an IP adddress (or any available method that allows us to connect
to DB2 from another machine). I know we can do it in Java via JDBC in
the following fashion (suppose my IP address is xx.x.x.xxx):

sun.jdbc.odbc.JdbcOdbcDriver=com.ibm.db2.jcc.DB2Dr iver
sun.jdbc.odbc.ConnectionUrl=jdbc:db2://xx.x.x.xxx:50000/mydb
sun.jdbc.odbc.UserId=db2inst1
sun.jdbc.odbc.Password=mypasswd

Is there a similar way for an application in C++ on Linux? Currently
the application has to be on the same machine as the DB2 server.

I'm using DB2 UDB Express Edition V8.2 for Linux.

Thanks.

Feb 27 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
mjf wrote:
I'd like to connect from any Linux machine to the DB2 on a Linux server
via an IP adddress (or any available method that allows us to connect
to DB2 from another machine). I know we can do it in Java via JDBC in
the following fashion (suppose my IP address is xx.x.x.xxx):

sun.jdbc.odbc.JdbcOdbcDriver=com.ibm.db2.jcc.DB2Dr iver
sun.jdbc.odbc.ConnectionUrl=jdbc:db2://xx.x.x.xxx:50000/mydb
sun.jdbc.odbc.UserId=db2inst1
sun.jdbc.odbc.Password=mypasswd

Is there a similar way for an application in C++ on Linux? Currently
the application has to be on the same machine as the DB2 server.


Install a DB2 client on the, well, client. Then you catalog the database on
the server at your client and go ahead happily accessing the database as if
it were a local one.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Feb 27 '06 #2

P: n/a
mjf
Hi Knut, thanks for the timely info! Is that the only way?

Feb 27 '06 #3

P: n/a
You always have to have a DB2 client installed on the client machine.
However, (and this is a little known tidbit of information) you can
skip the "catalog the database on the server at your client" step by
using a direct TCP/IP connection string with the SQLDriverConnect()
API. We made use of this option to the ibm_db2 extension in PHP to
enable you to connect to arbitrary DB2 databases on any machine
(assuming you have the user ID and password).

/* Substitute database, hostname, port number, user ID, and password
values */
SQLCHAR *conn = "DRIVER={IBM DB2 ODBC
DRIVER};DATABASE=myDb;HOSTNAME=hostname;PORT=50000 ;PROTOCOL=TCPIP;UID=db2inst1;PWD=password;";

rc = SQLDriverConnect((SQLHDBC)conn_res->hdbc, (SQLHWND)NULL,
conn, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT );

Dan

Feb 28 '06 #4

P: n/a
mjf

Dan Scott wrote:
You always have to have a DB2 client installed on the client machine.
However, (and this is a little known tidbit of information) you can
skip the "catalog the database on the server at your client" step by
using a direct TCP/IP connection string with the SQLDriverConnect()
API. We made use of this option to the ibm_db2 extension in PHP to
enable you to connect to arbitrary DB2 databases on any machine
(assuming you have the user ID and password).

/* Substitute database, hostname, port number, user ID, and password
values */
SQLCHAR *conn = "DRIVER={IBM DB2 ODBC
DRIVER};DATABASE=myDb;HOSTNAME=hostname;PORT=50000 ;PROTOCOL=TCPIP;UID=db2inst1;PWD=password;";

rc = SQLDriverConnect((SQLHDBC)conn_res->hdbc, (SQLHWND)NULL,
conn, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT );

Dan


Dan, thanks!!

Feb 28 '06 #5

P: n/a
Dan Scott wrote:
You always have to have a DB2 client installed on the client machine.
However, (and this is a little known tidbit of information) you can
skip the "catalog the database on the server at your client" step by
using a direct TCP/IP connection string with the SQLDriverConnect()
API.


Please keep in mind that in V8 there is no AUTHENTICATION= keyword in
SQLDriverConnect() connection string.
Consequently - for DSN-less connections AUTHENTICATION=CLIENT is assumed causing
- on Windows - a trip to domain controller and possible slowdown before
shipping connection to remote server.

Jan M. Nelken
Mar 2 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.