Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBI->connect Failure Diagnostics 2

Status
Not open for further replies.

cartw19

Programmer
Feb 11, 2003
8
GB
How do I find out why a DBI->connect fials.

Using DBI to connect to an Oracle datbase, the connect fails but no diagnostics in the die clause produce anything.
e.g. $dbh = DBI->connect("dbi:Oracle: ...) or
die "Failed: $! $dbh->errstr $ora_errstr \n";
produces only the Failed text.
 
Try:

$dbh = DBI->connect($data_source, $username, $password)
or die $DBI::errstr;

Since DBI->connect() returns undef on failure, the object you are expecting ($dbh) is never instantiated. Thus attempting execute a method of a non-existent object will be nonfulfilling, and ultimately drive you to the edge.

Let us know if that works, I've had problems with connecting to Oracle in the past, it can get REAL screwy. Especially if your DBA f's with the config files w/o knowing what he's doing.

--jim
 
Oh yea, and just to confirm that DBD::Oracle (Oraperl.pm whatever) is installed:

perl -MDBI -le 'print for DBI->available_drivers'

--jim
 
neat one liner Jim

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Jim,
The &DBI::errstr still produced nothing.
Your one liner did show Oracle in the list of Drivers.

Thanks for the effort.

p.s. I solved the original problem by removing 2 $ENV statements, (1 for ORACLE_HOME on the server, and 1 for TNS_ADMIN pointing to the tnsname.ora file on the PC). these had been added during development of the script, and were no longer required.

Colin
 
Colin, good job on solving the problem. I'm curious however, that the connect() was dying but not showing the $DBI::errstr. Did you use &DBI::errstr or $DBI::errstr?

Hey Mike, back in the good old days I used to not really worry about the one liners, but any more I'm enjoying them. Good for quick debugging. Another one I have found myself doing often (to quickly discover the paths to used modules, SOAP::Lite for instance), is:

perl -MSOAP::Lite -le 'print "$_ => $INC{$_}" for keys %INC'

That's more for the other folks, since I believe you've been doing this just as long as I have. Possibly longer. :)

--jim
 
Are you trying to say I'm old!!!?

LOL

And yes - one liners can be useful.

And yeah... The $DBH::errstr thing should have worked just fine.... puzzling.

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Jim, definitely $DBI::errstr.
If I force another error - like wrong port number, I do get an error message, but with my original code, nothing.
Colin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top