Topic
  • 3 replies
  • Latest Post - ‏2013-10-01T17:15:33Z by Amy Tang
E497_omer_orlev
E497_omer_orlev
2 Posts

Pinned topic using activestate perl 5.10 and dbd:db2 to access DB2 on windows.

‏2010-10-15T18:52:24Z |
hey all,
i'm trying to run scripts that will query different DB2 queries and return the results via perl.

i'm using activestate perl 5.10.

i installed DB2 9.7 Enterprise server on a windows 2003 server,
then i installed the DBI module and the DBD:DB2 module.

i'm trying to run the following code as an example:
use DBI;
use strict;
  1. Open a connection
my $dbh = DBI->connect("dbi:DB2:omer1", "administrator", "omer2312", {RaiseError => 1});
  1. use VALUES to retrieve value from special register
my $stmt = "Values CURRENT DATE";
my $sth = $dbh->prepare($stmt);
$sth->execute();
  1. associate variables with output columns...
my $col1;
$sth->bind_col(1,\$col1);
while ($sth->fetch) { print "Today is: $col1\n"; }
$sth->finish();
$dbh->disconnect();

but i get the following error:
DBI connect('omer1','administrator',...) failed: Total Environment allocation failure! Did you set up your DB2 client environment? at C:\Documents and Settings\Administrator\Desktop\DB2\Not Ready\try.pl line 4

i tried to look this up on the web but couldn't find any answers for windows,
only linux.
i read something about environment variables, but i'm not sure which and to what path.

any ideas, anyone?
  • pdevarar
    pdevarar
    1 Post

    Re: using activestate perl 5.10 and dbd:db2 to access DB2 on windows.

    ‏2010-10-17T15:29:39Z  
    Hi Omer,

    Set the environment variable DB2INSTANCE to your instance name and you should get going.

    Eg: set DB2INSTANCE=db2

    Thanks

    Praveen
  • Amy Tang
    Amy Tang
    2 Posts

    Re: using activestate perl 5.10 and dbd:db2 to access DB2 on windows.

    ‏2013-10-01T17:10:02Z  
    • pdevarar
    • ‏2010-10-17T15:29:39Z
    Hi Omer,

    Set the environment variable DB2INSTANCE to your instance name and you should get going.

    Eg: set DB2INSTANCE=db2

    Thanks

    Praveen

    I hit the same issue on Windows, but set DB2INSTANCE=<instance_name> doesn't work for me, any idea? Basically I catalog the remote database (on linux host) on my windows client, then use DBI->connect to connect to it, got the similar error above. The script works well on linux machine though. I can connect to the remote database directly outside the script. Just DBI->connect hit issue. Appreciate any help?

  • Amy Tang
    Amy Tang
    2 Posts

    Re: using activestate perl 5.10 and dbd:db2 to access DB2 on windows.

    ‏2013-10-01T17:15:33Z  

    Hi, how was the issue solved? I got the same error on Windows, but the above suggestion seems not working for me. Thanks for any help!