473,473 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
5 3536
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
mjf
Hi Knut, thanks for the timely info! Is that the only way?

Feb 27 '06 #3
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Kona | last post by:
Hello, Is it right to tell that DB2 Connect has the same function that Oracle Net ? If I have an ODBC application is it also right to tell that I have 2 possibilities on my client workstation to...
4
by: banz | last post by:
Hello I have a problem to resolve: I wrote a Perlscript which caches data from a server (local on my machine) I would like to have a other connection to a remote server but I don't know how to...
8
by: Julia | last post by:
Hi, My client uses a remote object when I host the remote object inside a windows application all seem to work fine but when I host the same object inside a windows service I get the following...
5
by: smatta | last post by:
I have just installed MySql version 5.0-18 on Red Hat Fedora Core 4. It is running but I cant connect to it using MySql Query Browser running on my pc. >From my pc, I can telnet to the sql...
2
by: SB | last post by:
Hi, To connect to the DB2 Driver, from a remote machine. Do we requier DB2 client. Can't we connect by just having IBM DB2 driver which is just a single file (db2cli.dll). I am using vb...
14
by: Marcus | last post by:
I have a function that simply returns TRUE if it can connect to a particular Sql Server 2005 express, or FALSE if it cannot. I am getting some strange error codes returned when the computer that...
0
by: tamayi | last post by:
I have a problem (like most others posting issues on this forum :) ) I have a remote server running Windows XP SP2, with both SQL Server 2005 Express with Advanced Features and SQL 2000...
1
by: ganeshp | last post by:
Hi All, One programming technique to connect from one system to other is through socket programming. Socket programming can be done using programming languages like Java,C,C++. Are there any...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.