rajesh_perl has asked for the wisdom of the Perl Monks concerning the following question:

I have written simple DB connectivity program, i am getting the following error, plesae advice ?
use strict; use warnings; use DBI; # . /opt/CA/WorkloadAutomationAE/autouser.DEV/autosys.sh.`hostname` # TNS_ADMIN = "/usr/oracle/product/11.2.0.4/network/admin"; my $driver = "Oracle"; my $database = "ASYSDEV2"; my $dsn = "DBI:$driver:database=$database"; my $userid = "autosysr"; my $password = "A13sm_sd"; my $dbh = DBI->connect($dsn, $userid, $password ) or die $DBI::errstr;
Error :
DBI connect('database=ASYSDEV2','autosysr',...) failed: ORA-12154: TNS +:could not resolve the connect identifier specified (DBD ERROR: OCISe +rverAttach) at perl_DBI.pl line 15 ORA-12154: TNS:could not resolve the connect identifier specified (DBD + ERROR: OCIServerAttach) at perl_DBI.pl line 15.
  • Comment on ORA-12154: TNS:could not resolve the connect identifier specified (DBD ERROR: OCIServerAttach)
  • Select or Download Code

Replies are listed 'Best First'.
Re: ORA-12154: TNS:could not resolve the connect identifier specified (DBD ERROR: OCIServerAttach)
by marto (Cardinal) on Mar 28, 2017 at 06:23 UTC

    Welcome, please format your post accordingly, currently it's unnecessarily difficult to follow. How do I post a question effectively?. Also please post the appropriate sections of tnsnames.ora and listener.ora. Perhaps you're not setting your ORACLE_HOME environment variable properly. A quick test is to set this in your perl script before you try to connect. The DBD::Oracle documentation mentions this.

Re: ORA-12154: TNS:could not resolve the connect identifier specified (DBD ERROR: OCIServerAttach)
by cbeckley (Curate) on Mar 28, 2017 at 13:59 UTC

    I think you need:

    my $dsn = "dbi:$driver:$database";

    Of course this assumes this is a local database, and that $ORACLE_HOME is set appropriately.

    If the database is not local, you will need to invoke connect with a host, and possibly a port.

    Hope that helps

    Thanks,
    cbeckley

Re: ORA-12154: TNS:could not resolve the connect identifier specified (DBD ERROR: OCIServerAttach)
by afoken (Chancellor) on Mar 30, 2017 at 16:28 UTC
    TNS:could not resolve

    It's been a while since I've last used Oracle, but it looks like your TNSNAMES.ORA file is incomplete or missing. Maybe there is also a SQLNET.ORA file that disables TNSNAMES.ORA. Contact your Oracle admin for help. Try reading 1 and 2, it's knowledge from the days of Oracle 9 and 10, but still helps some people.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: ORA-12154: TNS:could not resolve the connect identifier specified (DBD ERROR: OCIServerAttach)
by madtoperl (Hermit) on Mar 28, 2017 at 08:48 UTC