Hello,
I want to use DBI to connect to MS Access database. In my code, I
have:
#!c:/perl/bin/perl.exe
use CGI qw(:standard :html);
use DBI;
$DBase="C:\db1.mdb";
my $dbh=DBI->connect('dbi:ODBC:$DBase')
or die "Can`t connect to database: " . DBI->errstr;
.....
But I get this error:
install_driver(ODBC) failed: Can't locate DBD/ODBC.pm in @INC(@INC
contains: c:/Perl/lib c:/Perl/site/lib.
Perhaps the DBD::ODBC perl module hasn't been fully installed,
or perhaps the capitalisation of 'ODBC' isn't right.
Available drivers: ADO, ExampleP, Oracle, Proxy.
How do I tell if DBD::ODBC perl module is fully installed?
I do have these files:
c:/Perl/lib/Win32/Odbc.pm
c:/Perl/site/lib/Win32/ODBC.pm
My Perl version is 5.005_3 for MSWin32-x86, and the ODBC installed on
the computer was from the file Win32_ODBC_Build_311(1).zip, which was
last modified in 1998.
I also tried to use Win32::ODBC instead of DBI. The code is:
use Win32::ODBC;
$DSN="Win32 ODBC Test";
$DriverType = "Microsoft Access Driver (*.mdb)";
$DBase="C:\SNPseq.mdb";
$Dir="C:";
if (Win32::ODBC::ConfigDSN(ODBC_ADD_DSN, $DriverType, ("DSN=$DSN",
"Description=The Win32 ODBC Test DSN for Perl", "DBQ=$DBase",
"DEFAULTDIR=$Dir", "UID=", "PWD=")))
{ print "Successful!\n";
}else{
print "Failure\n";
}
print "Opening ODBC connection for \"$DSN\"\n";
if (!($O = new Win32::ODBC($DSN))){
print "Failure. \n\n";
$Failed{'Test 3a'} = "new(): " . Win32::ODBC::Error();
exit();
}else{
print "Success (connection #", $O->Connection(), ")\n\n";
}
I was able to add a new DSN, but I cannot get a new connection. What
was the problem?
Thanks a lot for your help on my questions.
Best,
Changhong