Connect perl access to ms

I am trying to retrieve data from a table in access. The code

#!/usr/bin/perl  
use strict;  
use warnings;  
use DBI;  
my $DBFile  = qw(C:test\INSTRUCTIONS.mdb );   
my $dbh = DBI->connect("dbi:ODBC:driver=microsoft access driver (*.mdb);dbq=$DBFile",'','') or die("cannot connect to DB");  
my $SQLquery = "select * FROM IndemDate";  
$dbh->Execute($SQLquery);  

This is the error I get

DBI connect('driver=microsoft access driver (*.mdb);dbq=C:test\INSTRUCTIONS.mdb','',...) failed: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (SQL-IM002) at C:/Test/connectaccess.pl line 9.
cannot connect to DB at C:/Test/connectaccess.pl line 9.

can someone help me fix my mistake. Is there a driver that I skipped for installation.

+3
source share
3 answers

As stated in the comments on the question, the Perl script was initially executed as a 64-bit process. Therefore the old Microsoft Jet Jet ODBC driver

Microsoft Access Driver (*.mdb)

not available. Only more than 32-bit processes can use the old Jet driver. If you must run the Perl script as a 64-bit process, you will have to download and install the 64-bit version of the new Microsoft Access Database Engine (aka ACE) from here , and then use the driver name

Microsoft Access Driver (*.mdb, *.accdb)

Perl script 32- Jet.

re:

32- Access 2007, 32- ACE . 64- ACE-, 64- ACE , 32- Office . (-, , , , Office .)

, :

  • Perl script 32-

  • 32- Access 2007 64- Access, Perl script 64- , 64- ACE.

+3

Jet:

#!/usr/bin/perl -w
use strict;
use warnings;

use Win32::OLE;

my $DBFile  = qw( C:\test\INSTRUCTIONS.mdb );

# choose the appropriate versione of Jet for your system
my $Jet = Win32::OLE->CreateObject('DAO.DBEngine.36') or die "Can't create Jet database engine.";

my  $DB = $Jet->OpenDatabase( $DBFile );
my $SQLquery = "select * FROM IndemDate";
$DB->Execute($SQLquery, 128); #128=DBFailOnError

[: , ]

0

For a script running as a 32-bit process (in my case, 32-bit Strawberry Perl), the following code works for me:

#!perl  
use strict;  
use warnings;  
use DBI;  
print 'bits: ' . (8 * (length pack 'P', -1)) . "\n\n";
my $DBFile = q(C:\Users\Public\mdbTest.mdb);   
my $dbh = DBI->connect("dbi:ODBC:Driver={Microsoft Access Driver (*.mdb)};DBQ=$DBFile",'','') or die("cannot connect to DB");  
my $SQLquery = "SELECT * FROM Members";  
my $sth = $dbh->prepare($SQLquery);
my $rc = $sth->execute;
while (my $href = $sth->fetchrow_hashref) {
    print "memberID: " . $$href{"memberID"} . "\n";
    print "memberName: " . $$href{"memberName"} . "\n";
    print "\n";
}
0
source

All Articles