Jump to content

[SOLVED] ORA-12154: TNS:could not resolve the connect identifier specified

Recommended Posts

Hello guys,

Ok, i'm working on php/mysql but now i want to deal with oracle (on other server),

So i installed instantclient-sqlplus-win32 for oracle, and when i open phpinfo page, the oci8 is enabled :)


But my problem is when i connect to db, this error is show up


ORA-12154: TNS:could not resolve the connect identifier specified


My coonect code:

// try connecting to the database
$conn = oci_connect('username', 'password', 'host');

// check for any errors
if (!$conn)
$e = oci_error();
print htmlentities($e['message']);

// else there weren't any errors
echo 'I am an Oracle mack daddy.';


I checked from the file tnsname.ora


But when i searched on google to find solution, i read that it should be a file named sqlnet.ora


And i don't have this file...


Is this my problem??


Shall i got both sqlnet.ora and tnsname.ora files??


Please i need help as soon as possible



Link to post
Share on other sites

The tnsnames.ora file is like DNS for oracle instances.  Basically what that error is telling you is that it can't convert the oracle instance name you're providing to a Server/IP/Port combination.


The sqlnet.ora file allows you to configure sql*net which is oracle's network protocol. 


Needless to say, these are 2 totally seperate things. 


With that said, you probably want to try and use the oracle connection string that allows you to circumvent the need for a tnsnames.ora file. 


There's a nice summary blog post here:  http://alisonatoracle.blogspot.com/2006/02/oracle-database-connection-strings-in.html

Link to post
Share on other sites

Hi gizmola,


Thanks for replying, i read the site you suggested, it's really helpful..

But my problem now as the following:

When i write in the "run":

C:\Program Files\instantclient11 sqlplus username/password@db

It response and oracle information was showup..


BUT...when i try to access database through php code, the same error is appeared >:(


So, is the problem from my code, or something inside the tnsname.ora? or the problem from the other server (which have oracle database)??


And BTW, i tried all three ways in the website with no respone





Link to post
Share on other sites
  • 2 weeks later...


Can you tnsping the database from that server?  It seems like you have a problem with your connect string.  If you can construct a valid tnsnames.ora entry and tnsping it, then that should allow you to connect using the verbose format.

Link to post
Share on other sites
  • 9 months later...

Sorry to bring back an old thread but I get the same error message "ORA-12154: TNS:could not resolve the connect identifier specified" When I simply try to connect in my php script using a SID.


Basically I can connect fine with sqlplus using the sid. I can connect with php if I supply the full string. But when I use the alias/SID with php it gives me this error.


I am 90% sure php see's the tnsnames.ora file because I get a different error if I use SERVICE_NAME instead of SID in the connection string.


I am using Red Hat Enterprise Linux 5, Apache 2.2 and PHP 5.2.9. Basically trying to setup a new server.


I use this script to setup my ENV Variables:


service httpd stop



echo Starting Apache 
service httpd start


Appreciate the help. Thanks


Link to post
Share on other sites

figured out php did not care about TNS_ADMIN and put a copy of the sqlnet.ora and tnsnames.ora in the $ORACLE_HOME/network/admin folder that I had to create. Hope this saves trouble for someone else



Link to post
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.