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

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?

Replies are listed 'Best First'.
Re: using DBD:DB2 with perl on DB2 for windows
by morgon (Priest) on Oct 15, 2010 at 20:01 UTC
    DB2 requires certain environment variables to be set (one is DB2INSTANCE I think but there may be more).

    You can either set them in the shell where you launch your script (how you do that depends on the shell - I think it is "SET <variable>=<value>" in cmd.exe) or you set them in a BEGIN-block in your script ($ENV{DB2INSTANCE}=<whatever>").

    Which variables to set to which value depends on your installation - best to ask your DBA.

      Thanks for the reply.

      the thing is, i'm able to connect to DB2 through its users interface with no problem..

      and i can't find any reference to the enviornment varibales necessary.

      i'm not sure that the enviornment variables are the issue in this case..

      does anyone have any experience with this?