Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

DBI ODBC!

by Anonymous Monk
on Feb 24, 2004 at 19:23 UTC ( [id://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'.
Re: DBI ODBC!
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

Re: DBI ODBC!
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.
Re: DBI ODBC!
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.


    Grygonos

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-03-28 08:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found