Perl: the Markov chain saw | |
PerlMonks |
RFC: Oracle Perl Connectionby sqlpython (Novice) |
on Nov 24, 2009 at 19:34 UTC ( [id://809180]=perlmeditation: print w/replies, xml ) | Need Help?? |
I don't usually visit here. I should change that fact. So I thought I would share a solution that helped me. I apologize if this has publised before as I did not find this here. I am really a MySQL user for many years. Recently I had to deal with Oracle which I had not touched in 9+ years. So I needed a Quick Strategy to Connect to Oracle DB from Perl script. I hope this helps someone else... "My Thanks to Michael's Blog for this ... After successful installation of DBD::Oracle it’s time to use it. The connection string is the same as for he rest DB: my $dbi=
As result of running code above I got following error: Couldn't connect to database db_name: ORA-12154: TNS:could not resolve the connect identifier specified (DBD ERROR: OCIServerAttach)After googling I found that the problem was that. I tried to connect to the remove database but the driver couldn’t do that without special file – tnsnames.ora. It should be placed to the $ORACLE_HOME/network/admin and contain something like that:
And the connection string should be changed to use service name from the tnsnames.ora instead of host: my $dbi = DBI->connect("dbi:Oracle:$service_name", $db_user, $db_pass);Finally we should export variable ORACLE_SID into our environment. Add this command into .bashrc export ORACLE_SID="orcl"or set it using Perl variable $ENV: $ENV{ORACLE_SID} = 'orcl';
Back to
Meditations
|
|