Losing has asked for the wisdom of the Perl Monks concerning the following question:

It's me again, always with the database questions :(. I am trying to connect to a REMOTE DB2 database from a perl script. This is what I have:
use DBI; use strict; my $DSN = "dbi:DB2:DATABASE=$db; HOSTNAME=$hostname; PORT=$port; PROTO +COL=TCPIP; UID=$user; PWD=$pass;"; my dbh = DBI->connect($DSN, $user, $pass)or die $DBI::errstr;
I get an invalid argument value error, SQLSTATE=HY009.

I cannot for the life of me figure out what is wrong with this code. I can connect fine to the local DB2 database, but I cannot connect to the remote database. Any ideas?

Replies are listed 'Best First'.
Re: Connecting to a remote DB2 database
by neilwatson (Priest) on Nov 30, 2006 at 21:33 UTC
    Did check the contents of '$!'? Can you connect to the remote server using a local client?

    Neil Watson
    watson-wilson.ca

      I can connect to the server if I catalog the remote server and you the data source name alias. But this is most inconvenient, im looking for a way to connect to a remote DB2 database with nothing other than the actual script. Maybe this is not possible?
Re: Connecting to a remote DB2 database
by Tanktalus (Canon) on Dec 01, 2006 at 03:39 UTC

    Looking on IBM's site for HY009 seems to point to a C code errror ... which, if this is all you're doing, apparently straight out of the DBD::DB2 docs, doesn't seem like a reasonable return code for that operation. So I'd suggest opening a PMR with IBM.

    Personally, I've always just cataloged the remote db's locally - it makes for easier debugging when I can just run quick command-line queries to see what I'm doing wrong. I also like how I can have an instance that catalogs a test database, and just recatalog the database alias to point at the production instance when I'm done testing. ;-)