Pb using OLE with Access

B

Bolin

I have a problem accessing a MSAccess database via OLE. The following
code:

############################
use WIN32::OLE;
use Win32::OLE::Const;

my $DBfile = "c:\\data.mdb";

my $Conn = Win32::OLE->new("ADODB.Connection") or die "Object creation
failed: $!\n";
my $RS = Win32::OLE->new("ADODB.Recordset") or die "Object creation
failed: $!\n";

my $DSN = "PROVIDER=MSDASQL;DRIVER={Microsoft Access
Driver(*.mdb)};DBQ=$DBfile;UID=;PWD=;";

$Conn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=$DBfile") or
die "$!\n";
############################

dies at the last line with a "No such file or directory", although the
file is there -- I really don't know what is going on. Did somebody
run into the same error? I am using perl v5.8.0 build 806 provided by
ActiveState on Windows 2000.

Thanks for your help,

G.
 
J

Jay Tilton

(e-mail address removed) (Bolin) wrote:

: ############################
: use WIN32::OLE;
: use Win32::OLE::Const;
: my $DBfile = "c:\\data.mdb";
: my $Conn = Win32::OLE->new("ADODB.Connection") or die "Object creation
: failed: $!\n";
: my $RS = Win32::OLE->new("ADODB.Recordset") or die "Object creation
: failed: $!\n";
: my $DSN = "PROVIDER=MSDASQL;DRIVER={Microsoft Access
: Driver(*.mdb)};DBQ=$DBfile;UID=;PWD=;";
: $Conn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=$DBfile") or
: die "$!\n";
: ############################
:
: dies at the last line with a "No such file or directory", although the
: file is there -- I really don't know what is going on.

$! has nothing to do with OLE errors.

Win32::OLE->LastError() will return an error message indicating the real
trouble.
 
B

Bob Walton

Bolin said:
I have a problem accessing a MSAccess database via OLE. The following
code:

############################
use WIN32::OLE;

in-----^^
Case matters in module names -- even on Windoze. It won't complain
about not finding the module, but it won't work, either.

use Win32::OLE::Const;

my $DBfile = "c:\\data.mdb";

my $Conn = Win32::OLE->new("ADODB.Connection") or die "Object creation
failed: $!\n";
my $RS = Win32::OLE->new("ADODB.Recordset") or die "Object creation
failed: $!\n";

my $DSN = "PROVIDER=MSDASQL;DRIVER={Microsoft Access
Driver(*.mdb)};DBQ=$DBfile;UID=;PWD=;";

$Conn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=$DBfile") or
die "$!\n";

-------^^
This won't pick up errors from Win32::OLE -- try
Win32::OLE->LastError(), perhaps.

Note here that the value returned by the Open method is a VB
success/failure value, which usually has the opposite sense from the
normal Perl sense -- 0 indicates success, -1 indicates failure. So are
you certain the Open is actually failing?

############################

dies at the last line with a "No such file or directory", although the
file is there -- I really don't know what is going on. Did somebody
run into the same error? I am using perl v5.8.0 build 806 provided by
ActiveState on Windows 2000. ....


G.

I suggest that unless you have a good reason for using Win32::OLE to
access Access, that you abandon it in favor of using the DBI module.
You can use it in conjunction with DBD::ODBC, which will give nice
convenient access to your Access database -- and the code will be
standard, so when you graduate to another database, all you will have to
do is revise the connect call.
 
B

Bolin

Bob Walton said:
-------^^
This won't pick up errors from Win32::OLE -- try
Win32::OLE->LastError(), perhaps.

Note here that the value returned by the Open method is a VB
success/failure value, which usually has the opposite sense from the
normal Perl sense -- 0 indicates success, -1 indicates failure. So are
you certain the Open is actually failing?

Indeed, that is where the error was -- without this buggy error
checking everything is working fine.

Thanks!

G.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,737
Latest member
Georgeengab

Latest Threads

Top