in reply to Accessing Access in Perl

I often use DBD::ODBC and the appropriate connection string from http://www.connectionstrings.com/.

Replies are listed 'Best First'.
Re^2: Accessing Access in Perl
by rpike (Scribe) on Sep 23, 2010 at 13:59 UTC
    Do you have a simple example? I'm trying a few approaches and none seem to work (the directory for the mdb specified below may differ from what I originally posted). For example,
    DBI->connect( "dbi:ODBC:driver=Microsoft Access Driver(*.mdb);dbq=C:/D +ownload/tmp/examples.MDB",'','') or die "Cannot open the file";
    I get the error : DBI connect('driver=Microsoft Access Driver(*.mdb);dbq=C:/Download/tmp/examples.MDB','',...) failed: MicrosoftODBC Driver Manager Data source name no t found and no default driver specified (SQL-IM002) at testScript.pl line 7 Cannot open the file at testScript.pl line 7.

      I use the following:

      $dsn ||= "dbi:ODBC:driver=Microsoft Access Driver (*.mdb);dbq=$dbfile" +;

      Note that I have different whitespace. I assume that whitespace is significant.

      $dbfile is a filename with backslashes, which should not be significant, but you might want to try both.

        I must have left something out cause although I thought that is what I had in there it didn't work. I copied your post and it appears to work. Do you have a very simple, generic piece a code that selects everything from the database and prints it to the screen? I'm uncertain of the format and what data is in this database so I need to loop through and print some of the content to screen. One great approach would be to see the structure of the database. I haven't worked on Access/SQL in such a long time so I apologize for some of these noob-like questions. Thanks so much for the help.

      I think you need to put {} around some key values in your connection string - they quote the value. Also you slashes are the wrong way around in the filespec.