Error trapping $RS_ADO->Open($SQL_ADO, $Conn_ADO, 1, 1)

G

Geek

Is there any way to trap for errors in the "->Open" statements below?

Thanks.

$Conn_ADO = Win32::OLE->new("ADODB.Connection");
$RS_ADO = Win32::OLE->new("ADODB.Recordset");

$DSN_ADO = "Provider=SQLOLEDB.1;Persist Security
Info=False;Database=DB1;Data Source=duh;UID=whatever;PWD=noway;Connect
Timeout=30";

$Conn_ADO->Open($DSN_ADO); #<-- *** This one ***

$SQL_ADO = <<EOF;
SELECT *
FROM TaskOrder
ORDER BY TaskID
EOF

$RS_ADO->Open($SQL_ADO, $Conn_ADO, 1, 1) #<-- *** And this one ***
 
B

Ben Liddicott

eval{
$Conn_ADO->Open($DSN_ADO); #<-- *** This one ***
}
if($@){
# Failed to open.
}

Or even better:

use Error;

try{
# do something that might die or croak.
$Conn_ADO->Open($DSN_ADO); #<-- *** This one ***

}otherwise{
# died or croaked. Do something about it.

};# don't forget the semicolon

See "perldoc Error" for more.

Cheers,
Ben Liddicott
 
B

Ben Liddicott

My mistake: If you want your objects to croak on error, you have to say:

Win32::OLE->Option(Warn=>3);

Otherwise you can check FAILED(Win32::OLE::LastError()), where:

sub FAILED($){$_[0] & 0x80000000;}
sub SUCCEEDED($){not ($_[0] & 0x80000000);}
$Conn_ADO->Open($DSN_ADO); #<-- *** This one ***
SUCCEEDED(Win32::OLE::LastError()) or croak(Win32::OLE::LastError());


Values of LastError without the top bit set are success codes, which you
won't see often.

There are other options too. perldoc Win32::OLE for more.

Cheers,
Ben Liddicott
 
G

Geek

Thank you very much! :)


Ben Liddicott said:
My mistake: If you want your objects to croak on error, you have to say:

Win32::OLE->Option(Warn=>3);

Otherwise you can check FAILED(Win32::OLE::LastError()), where:

sub FAILED($){$_[0] & 0x80000000;}
sub SUCCEEDED($){not ($_[0] & 0x80000000);}
$Conn_ADO->Open($DSN_ADO); #<-- *** This one ***
SUCCEEDED(Win32::OLE::LastError()) or croak(Win32::OLE::LastError());


Values of LastError without the top bit set are success codes, which you
won't see often.

There are other options too. perldoc Win32::OLE for more.

Cheers,
Ben Liddicott


Ben Liddicott said:
eval{
$Conn_ADO->Open($DSN_ADO); #<-- *** This one ***
}
if($@){
# Failed to open.
}

Or even better:

use Error;

try{
# do something that might die or croak.
$Conn_ADO->Open($DSN_ADO); #<-- *** This one ***

}otherwise{
# died or croaked. Do something about it.

};# don't forget the semicolon
 

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

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top