views:

447

answers:

1

I based my code on the answer to the question Access get all tables, but am getting the following error:

DBD::ODBC::st execute failed: [Microsoft][ODBC Microsoft Access Driver] Record(s) cannot be read; no read permission on 'MSysObjects'. (SQL-42000) at direct.pl line 22.

[Microsoft][ODBC Microsoft Access Driver] Record(s) cannot be read; no read permission on 'MSysObjects'. (SQL-42000) at direct.pl line 22.

Here is what I have tried so far. I commented out my first attempt. The current attempt is based on SELECT "Table" AS [Table] which astander mentioned in his answer to said question. I get the same error either way. Here is my code, in its entirety:

use strict;
use warnings;

use DBI;

my $dbh = DBI->connect('DBI:ODBC:MutantDB','','') 
    or die 'could not connect to database' . DBI::errstr;

my $sth = $dbh->prepare('SELECT "Table" AS [Table],
             MSysObjects.Name,
             MSysObjects.Type
             FROM MSysObjects
             WHERE MSysObjects.Type =1
             Or MSysObjects.Type=6
             ORDER BY MSysObjects.Name;')
    or die 'could not prepare statement' . $dbh->errstr();


# my $sth = $dbh->prepare('SELECT MSysObjects.*, MSysObjects.Type
#              FROM MSysObjects
#              WHERE (((MSysObjects.Type)=1)) OR (((MSysObjects.Type)=6));'
# ) or die 'could not prepare statment' . $dbh->errstr();

$sth->execute() or die $sth->errstr();

while( my ($name, $type) = $sth->fetchrow()){
    print "name: $name \t type: $type \n";
}
+1  A: 

How about a schema?

http://www.cpan.org/authors/id/T/TL/TLOWERY/DBD-ADO-2.1.readme

Remou
Thanks so much!
molecules
Here's a better link to DBD:ADO http://search.cpan.org/dist/DBD-ADO/lib/DBD/ADO.pm
daotoad
Thanks. From one of Sinan Ünür's edits of my posts, I learned that it can be even more concise. Use http://search.cpan.org/perldoc? followed by the module of interest, such as http://search.cpan.org/perldoc?DBD::ADO
molecules