Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Connect with DBI to Access 2007

by cfreak (Chaplain)
on Apr 15, 2008 at 16:51 UTC ( [id://680575]=perlquestion: print w/replies, xml ) Need Help??

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

I'm trying to connect to an Access database file on my local machine. I did this long ago with an older version of Access with no troubles but I can't seem to get it to work this time.

Here's the code:
use strict; use DBI; use Data::Dumper qw(Dumper); my $dsn = 'dbi:ODBC:driver=Microsoft Access Driver (*.mdb,*.accdb);' . 'dbq=C:\Database2.accdb'; my $dbh = DBI->connect($dsn, '','') or die DBI->errstr(); my $query = "SELECT * FROM Table1 LIMIT 1"; my $sth = $dbh->prepare($query); $sth->execute() or die $sth->errstr(); my $row = $sth->fetchrow_hashref(); print Dumper($row);

But all I get is "Data source name not found and no default driver specified (SQL-IM002)". I google this error and get basically that the file or the driver is wrong. But I've verified I have this driver (I've also tried it as Microsoft Access Driver (*.mdb) and the file is definitely there.

Basically I've wasted many hours on this now and I'm hoping someone has a solution!

Thanks in advance

Update

I got it to work using a DSN in the Data Sources console. Still not exactly what I want since reading the docs shows I should be able to do it without a DSN. Good enough for now, but if someone has done it without a DSN, please reply and let me know what I'm doing wrong. Thanks

Replies are listed 'Best First'.
Re: Connect with DBI to Access 2007
by tachyon-II (Chaplain) on Apr 16, 2008 at 00:54 UTC
Re: Connect with DBI to Access 2007
by Narveson (Chaplain) on Apr 15, 2008 at 19:14 UTC

    Good question. None of us seems to have come across the answer in the month since somebody else was unable to connect to Access 2007 from Perl.

    Like you, they got it to work using a DSN in the Data Sources console, but we never heard that they managed to connect to a filename given at runtime.

    Perhaps this belongs in a Frequently Unanswered Questions section.

Re: Connect with DBI to Access 2007
by cfreak (Chaplain) on Apr 16, 2008 at 02:53 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://680575]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-04-23 13:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found