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

Hi

I am using Perl 5.8.8 and i use

DBI->connect("dbi:ODBC:driver=Microsoft Access Driver (*.mdb );dbq=$fi +le"
to connect to access. This used to work with access 2000. but now in access 2007 the file extension has been changed to .accdb so i changed the code to
DBI->connect("dbi:ODBC:driver=Microsoft Access Driver (*.mdb, *.accdb) +;dbq=$file"
but it is giving error
[Microsoft][ODBC Microsoft Access Driver] Not a valid file name. (SQL- +HY000)(DBD: db_login/SQLConnect err=-1)
Can somebody help me to resolve this error.

Thanks

Replies are listed 'Best First'.
Re: Unable to connect to access 2007 from perl
by bingos (Vicar) on Mar 18, 2008 at 08:54 UTC

    Maybe try creating a system DSN for the Access 2007 file and use that with DBI instead

      I have tried this, this works. But the file will keep on changing. the file name will be accepted as argument to this file. So i cant create DSN and use it.
Re: Unable to connect to access 2007 from perl
by digger (Friar) on Mar 18, 2008 at 15:51 UTC

    Access 2007 makes significant changes to the database format. Microsoft provides additional data connection components for making ODBC connections to Access 2007. The only catch is that these components won't install on Windows 2000 Server.

    I don't have Access 2007 on the systems I am using now, so I can't thoroughly test it. Let us know if installing these additional components works for you.

      I downloaded the components and installed. but still i am getting same error. I am using DBI and ODBC to connect to acces, so do i need any extra modules or updated module for connecting to access 2007. This is my code : use DBI; my($file) = @ARGV; my $DSN = "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);dbq=$file"; print($DSN); $dbh = DBI->connect("dbi:ODBC:$DSN", '', '', { RaiseError => 0, AutoCommit => 0, PrintError => 0, LongReadLen =>1000, LongTruncOk => 1 })||die print $DBI::errstr;
        I have tried using the above suggestion. It still deos not work out for me
Re: Unable to connect to access 2007 from perl
by Anonymous Monk on Jan 08, 2010 at 22:04 UTC
    Hey, had the same issue, and after updating the MS component from the link also had the same error. Then I read on the MS website where the download link is that the syntax is now Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=path/file

    Note the curly brackets. All is well now.