FAQ
Hi Guys,
Can you guys help me with this error.
I am on an XP machine with ActivePerl installed along with DBI driver, DBD::DB2 driver
I am following instructions per this webpage:
http://www.ibm.com/developerworks/data/library/techarticle/dm-0512greenstein/

I am running a simple script to connect to a DB2 database, but the following error.
################################################
perl dbaseConnect.pl <username> <password>
DBD::db2 initialisation failed: Can't locate object method "driver" via package
"DBD::db2" at E:/Perl/site/lib/DBI.pm line 815.

Perhaps the capitalisation of DBD 'db2' isn't right. at dbaseConnect.pl line 10
################################################

My script
##########################################
#!/usr/bin/perl
use DBI;
$db2user = $ARGV[0];
$pasw = $ARGV[1];

# Open a connection
$dbh = DBI->connect( "dbi:db2:<database>:<Server>:50000", $db2user, $pasw )
or die "Can't connect to sample database: $DBI::errstr";
print "Connection is successful !!\n";
###########################################

Search Discussions

  • Brian Manning at Apr 14, 2011 at 7:51 pm

    On Thu, Apr 14, 2011 at 10:04 AM, Ritesh wrote:
    I am on an XP machine with ActivePerl installed along with DBI driver, DBD::DB2 driver
    I am following instructions per this webpage:
    http://www.ibm.com/developerworks/data/library/techarticle/dm-0512greenstein/

    I am running a simple script to connect to a DB2 database, but the following error.
    ################################################
    perl dbaseConnect.pl <username> <password>
    DBD::db2 initialisation failed: Can't locate object method "driver" via package
    "DBD::db2" at E:/Perl/site/lib/DBI.pm line 815.

    Perhaps the capitalisation of DBD 'db2' isn't right. at dbaseConnect.pl line 10
    I would say that the above error is pretty self explanatory.
    #!/usr/bin/perl
    use DBI;
    $db2user = $ARGV[0];
    $pasw = $ARGV[1];

    # Open a connection
    $dbh = DBI->connect( "dbi:db2:<database>:<Server>:50000", $db2user, $pasw )
    or die "Can't connect to sample database: $DBI::errstr";
    The web page you linked above has the following example database handle:

    $dbh = DBI->connect ("dbi:DB2:dbalias", $UserId, $password);

    Do you see the difference between the example database handle and your
    database handle?

    Thanks,

    Brian
  • Ritesh at Apr 15, 2011 at 6:20 pm
    Thanks Brian,
    I finally got this working. The DBD->connect syntax I was using was correct.
    The reason it was failing was because I did not define the database(that I want to connect to ) in the DB2 client configuration.
    Once I did that I was able to connect to the database. I did not realized that it was necessary to configure the database first. I thought that the script would allow me to directly connect to it.
    Anyways, here is my revised script for connection, in case anyone in the group want to use it.
    *************************************
    #!/usr/bin/perl
    use DBI;
    use DBD::DB2;
    use DBD::DB2::Constants;

    $db= 'dbname';
    $hostname='hostname';
    $user='name';
    $pass='password';
    my $string = "dbi:DB2:DATABASE=$db; HOSTNAME=$hostname;";
    my $dbh = DBI->connect($string, $user, $pass) || die "Connection failed with error: $DBI::errstr";
    print "Connection is successful !!\n";
    ******************************************

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdbi-users @
categoriesperl
postedApr 14, '11 at 5:05p
activeApr 15, '11 at 6:20p
posts3
users2
websitedbi.perl.org

2 users in discussion

Ritesh: 2 posts Brian Manning: 1 post

People

Translate

site design / logo © 2022 Grokbase