wmjie / ibm-db

Automatically exported from code.google.com/p/ibm-db
0 stars 0 forks source link

How to connect to a remote database. #56

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Sorry for the newbie question ...

What values for the ibm_db.connect() parameters will let me connect to
a remote database where

host     = "myhost.com"
port     = "1234"
dbname   = "mydatabase"
user     = "myname"
password = "mypassword

All my guesses, based on my experience with MySQL and Oracle, have failed.

Thanks in advance.

Original issue reported on code.google.com by jon.uc...@gmail.com on 22 Jul 2010 at 5:04

GoogleCodeExporter commented 9 years ago
create a connection string as follows
...
dsn = "DRIVER={IBM DB2 ODBC 
DRIVER};DATABASE=mydatabase;HOSTNAME=myhost.com;PORT=1234;PROTOCOL=TCPIP;UID=myn
ame;PWD=mypassword;"
...

and then pass it to connect API as follows
...
ibm_db.connect(dsn, '', '')
...

For more information about how to pass parameters in connect API please refer 
ibm_db google group thread 
http://groups.google.com/group/ibm_db/browse_thread/thread/1bddf36abf69c19d 

Original comment by rahul.pr...@in.ibm.com on 29 Jul 2010 at 12:40

GoogleCodeExporter commented 9 years ago
Thanks for the reply.

Unfortunately, the dsn string didn't work.  I get the error

   _db2.DatabaseError: ('I', -1, 'Invalid Handle')

Apparently, the failure occurs in the _db2 module before a remote connections is
even attempted.

Also unfortunately, I might not understand the pre-requisites for getting this 
to work.  Here's what I did.

1)  Installed DB2 Express-C database on Debian Lenny to get the necessary 
include
and library files for the next step.

2)  Compiled and installed the package PyDB2-devel-v1.1.tar.gz without errors.

Probably just as significantly, this is what I haven't done

1) I haven't installed ODBC (I tried once without success).

2) I haven't used DB2 Express-C to connect to the remote database, largely 
because I don't understand how to use it, and the docs seems to require that 
you learn all of them before you can use any of them.

Any suggestions you might offer would be appreciated.  If and when I get this 
to work, I'd like to document it for DB2 newbies like myself.

Thanks.

Original comment by jon.uc...@gmail.com on 4 Aug 2010 at 2:58

GoogleCodeExporter commented 9 years ago
Hi Jon,

We do not develop or maintain Pydb2. So, you need to install ibm_db first.
You can install ibm_db by issuing following command

...
easy_install ibm_db
...
or you can install it by using source code  available at 
http://pypi.python.org/pypi/ibm_db . There is a README file available inside 
source code which will help you through the installation process.

As communicated, you have already installed DB2 Express-C database which is 
more than enough to get it working.  There is no need to install ODBC.

You can find API description for the ibm_db driver at 
http://code.google.com/p/ibm-db/wiki/APIs

Thanks,
Rahul Priyadarshi

Original comment by rahul.pr...@in.ibm.com on 4 Aug 2010 at 8:46

GoogleCodeExporter commented 9 years ago
Sorry about the Pydb2 confusion.  I confused myself with an old attempt.

I mostly have it working now on a test system, except that our DB group is 
running version 7 DB2 versus current version 9.  It accepts a connection from 
ibm_db.connect() using the correct username/password and dsn format you 
supplied, but fails with this error

   Exception: [IBM][CLI Driver] SQL8002N  An attempt to connect to a host failed due to a missing DB2 Connect product or invalid license.  SQLSTATE=42968 SQLCODE=-8002

I'm guessing the fix for that will be to upgrade our DB to version 9?

For reference, I'll describe the installation procedure that worked for me in a 
follow-up post.

Original comment by jon.uc...@gmail.com on 5 Aug 2010 at 7:39

GoogleCodeExporter commented 9 years ago
How to install ibm_db on a fresh Ubuntu 10.04.  There may be an easier way, 
this is just what worked for me.

1) Install these Ubuntu packages
    > apt-get install libaio1 python-dev python-setuptools

2) As root, download and install IBM's DB2 Express-C package.  Choose a custom 
install, and select the software development files.  This is the most time 
consuming part.

3) Copy the db2 library file to /usr/local/lib as follows
    > cp -p ~db2inst1/sqllib/lib/libdb2.so.1 /usr/local/lib
    > ldconfig

4) Install ibm_db
    > export IBM_DB_DIR=~db2inst1/sqllib
    > export IBM_DB_LIB=~db2inst1/sqllib/lib
    > easy_install ibm_db

That completes the install.  This is how I tested it.  Make a file like this 
(NOTE:
replace  %(name)s, %(host)s, %(port)s, with your database name, host, port, 
etc.).

import ibm_db
DSN="DRIVER={IBM DB2 CLI 
DRIVER};DATABASE=%(name)s;HOSTNAME=%(host)s;PORT=%(port)s;PROTOCOL=TCPIP;UID=%(u
ser)s;PWD=%(pass)s;"
conn = ibm_db.connect(dsn,'','')

Run file like this
  > python test.py

Good luck.

Original comment by jon.uc...@gmail.com on 5 Aug 2010 at 7:49

GoogleCodeExporter commented 9 years ago

Original comment by rahul.pr...@in.ibm.com on 6 Aug 2010 at 6:04

GoogleCodeExporter commented 9 years ago
I tried this:

create a connection string as follows
...
dsn = "DRIVER={IBM DB2 ODBC 
DRIVER};DATABASE=mydatabase;HOSTNAME=myhost.com;PORT=1234;PROTOCOL=TCPIP;UID=myn
ame;PWD=mypassword;"
...

and then pass it to connect API as follows
...
ibm_db.connect(dsn, '', '')

but I got this:;
SystemError: error return without exception set

Original comment by hwang....@gmail.com on 17 Oct 2012 at 4:07

GoogleCodeExporter commented 9 years ago
using ibm_db-1.0.2-py2.6-linux-x86_64.egg on red hat enterprise 5.3

Original comment by hwang....@gmail.com on 17 Oct 2012 at 5:04

GoogleCodeExporter commented 9 years ago
could you upgrade the ibm_db module and let us know if you still having same 
problem.

Original comment by rahul.pr...@in.ibm.com on 18 Oct 2012 at 5:26

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I can not find the download for 2.0.0 py2.6 linux64

Original comment by hwang....@gmail.com on 18 Oct 2012 at 3:01

GoogleCodeExporter commented 9 years ago
You can install the latest version of ibm_db by issuing "$easy_install ibm_db" 
and make sure that you already have set the environment variable IBM_DB_HOME to 
<path_to_sqllib> .

Please let me know in case of any problem

Original comment by rahul.pr...@in.ibm.com on 22 Oct 2012 at 6:01

GoogleCodeExporter commented 9 years ago
thanks, Rahul, I solved the problem, I did not set the env vars correctly.

Original comment by hwang....@gmail.com on 22 Oct 2012 at 4:49