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:

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

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

// else there weren't any errors
else
{
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

 

Thanks

Link to comment
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 comment
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

 

Thanks,

 

Piba

Link to comment
Share on other sites

  • 2 weeks later...

Piba, 

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 comment
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:

#!/bin/sh

service httpd stop

LD_LIBRARY_PATH=/usr/lib/oracle/11.1/client/lib:${LD_LIBRARY_PATH}
TNS_ADMIN=/home
NLS_LANG=AMERICAN_AMERICA.UTF8


export LD_LIBRARY_PATH TNS_ADMIN NLS_LANG

echo Starting Apache 
service httpd start

 

Appreciate the help. Thanks

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.