Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine


by Anonymous Monk
on Feb 24, 2004 at 19:23 UTC ( #331494=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Heya! I'm forced to use an Access database within my project, and am attempting to use DBI::ODBC to connect to my Access file (users.mdb). However, i cannot seem to find sufficient data to learn this procedure outside of the perldoc functions, this is what i have so far...
my $dsn = "DBI:ODBC:driver=Microsoft Access;dbq=users.mdb"; my $dbh = DBI->connect($dsn,'','') or die "Cannot Connect to Server";
However, this doesn't connect, it says it "cannot connect to server". Could anybody point me in the direction of any good DBI::ODBC tutorials ?

Any help is appreciated, thank you!

BazB added code tags.

Replies are listed 'Best First'.
by hardburn (Abbot) on Feb 24, 2004 at 19:32 UTC

    You could change that to die "Cannot connect to server: " . DBI->errstr; to show why it failed.

    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

by matija (Priest) on Feb 24, 2004 at 19:44 UTC
    First, read the examples at the bottom of DBD::ODBC pod file (visible when you do perldoc DBD::ODBC.

    You will find the file contains links to a number of documents about DBD::ODBC. (I won't repeat the links - it's better if you read the doc).

    It also contains this example:

    my $DSN = 'driver=Microsoft Access Driver (*.mdb);dbq=\\\\cheese\\g$\\ +perltest.mdb'; my $dbh = DBI->connect("dbi:ODBC:$DSN", '','') or die "$DBI::errstr\n" +;
    As well as caveats about what you should check if the connection is failing.
by Grygonos (Chaplain) on Feb 24, 2004 at 20:03 UTC

    Greetings fellow victim of legacy Access databases. First things first. Make sure your database is setup as a DSN in your ODBC Data Sources Window. If you're on 2k/XP this is under the administrative tools menu. If you're on a 9x based system then check around the Control Panel... its bound to exist in there somwhere

    For my old Access work I simply did  my $dbh = DBI->connect('DBI:ODBC:'.$my_db_name) or die "$dbh->errstr"; Just make sure you set it up so Windows knows that you will be connecting to it via ODBC.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://331494]
Approved by gmax
[Discipulus]: yes, some semantic for the searxh must implemented before using such kind of query
[Corion]: Yeah - I have either to come up with a better search query or simply steal the template of some other file download site... I'm thinking of turning the JSON for Strawberry Perl releases into a small website that offers the files for download, with a ...
[Corion]: ... separate page per release, and potentially RSS for the versions

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2017-02-28 08:35 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (398 votes). Check out past polls.