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 | |
|
Re: Connect with DBI to Access 2007
by cfreak (Chaplain) on Apr 16, 2008 at 02:53 UTC |