while running a java application,I am getting ORA- 12154 error.
In the java application we have to Login using our Database credentials. For some user credentials the application is running successfuly but for others it's throwing error ORA-12154:TNS:could not resolve the connect identifer specified.
Can someone please help me with the issue.
The most usual cause for that is that database alias (you're connecting to) isn't included into the TNSNAMES.ORA file.
If you have several Oracle software products, there's a good chance that each of them has its own TNSNAMES.ORA file (usually located in its \network\admin directory). The way of it is to simultaneously edit all those files (which is stupid), or create a TNS_ADMIN environment variable which will point to a directory that contains your "master" TNSNAMES.ORA file, such as I have:
M:\>set tns_admin
TNS_ADMIN=C:\0_Oracle_library
Therefore, every time I have to add a new database, I edit that TNSNAMES.ORA file and all my Oracle programs (Forms, Reports, SQL Developer, TOAD, SQL*Plus, ...) access it and use it.
The Oracle error code documentation has some helpful troubleshooting tips (the following is from 12.1):
ORA-12154: TNS:could not resolve the connect identifier specified
Cause: A connection to a database or other service was requested using a connect identifier, and the connect identifier specified could not be resolved into a connect descriptor using one of the naming methods configured. For example, if the type of connect identifier used was a net service name then the net service name could not be found in a naming method repository, or the repository could not be located or reached.
Action:
If you are using local naming (TNSNAMES.ORA file):
- Make sure that "TNSNAMES" is listed as one of the values of the NAMES.DIRECTORY_PATH parameter in the Oracle Net profile (SQLNET.ORA)
- Verify that a TNSNAMES.ORA file exists and is in the proper directory and is accessible.
- Check that the net service name used as the connect identifier exists in the TNSNAMES.ORA file.
- Make sure there are no syntax errors anywhere in the TNSNAMES.ORA file. Look for unmatched parentheses or stray characters. Errors in a TNSNAMES.ORA file may make it unusable.
If you are using directory naming:
- Verify that "LDAP" is listed as one of the values of the NAMES.DIRETORY_PATH parameter in the Oracle Net profile (SQLNET.ORA).
- Verify that the LDAP directory server is up and that it is accessible.
- Verify that the net service name or database name used as the connect identifier is configured in the directory.
- Verify that the default context being used is correct by specifying a fully qualified net service name or a full LDAP DN as the connect identifier.
If you are using easy connect naming:
- Verify that "EZCONNECT" is listed as one of the values of the NAMES.DIRECTORY_PATH parameter in the Oracle Net profile (SQLNET.ORA).
- Make sure the host, port and service name specified are correct.
- Try enclosing the connect identifier in quote marks. See the Oracle Net Services Administrators Guide or the Oracle operating system specific guide for more information on naming.
Start by checking whether you can tnsping the specified service (tnsping is a utility included in the Oracle Client). For example, if connecting as x/y#zzz fails with ORA-12154, then
tnsping zzz
This will probably give
TNS-03505: Failed to resolve name
but it will also display the path of the local sqlnet.ora parameter file mentioned above. Depending on your setup there should be other .ora files in the same location.
There are a number of ways this can be configured depending on your OS, Oracle client and name resolution setup. (Note that a tnsnames.ora file is not the only naming method.) If you share some more details it should be straightforward to resolve the issue.
Related
I'm having an issue making a proxy database connection to an ORACLE database using ODP.net. I need my program to attempt the proxy connection but then prompt me for my certificate and authenticate me with that.
I have a Perl script that does this and it only requires me to specify the name of the TNS entry and the user I want proxying in for me.
I also have my SQL Developer doing the same thing, pointing to the same TNS entry.
But when I try to attempt the same approach with ODP.NET it just gives me the ORA-12154 error, "TNS: Could not resolve the connect identifier specified."
From my limited knowledge of Oracle I ASSUME that the error means that it couldn't find that TNS entry. And I've verified that the entry DOES exist in my tnsnames.ora file and proved I could proxy to it via my Perl script and SQL Developer. Even put a breakpoint in my VB code to ensure I was specify the correct TNS Entry.
I've even stripped down the connection string to JUST the datasource to see what error I get. So I'm not sure if I have the connection string wrong or if it needs to be in a different format. But I DO know that the solution HAS to allow me to specify the TNS alias and the connection HAS to prompt me for my certificate. No password.
So I guess I'm trying to find out what the appropriate connection string would look like to do this and why .NET can't seem to figure out what this TNS alias is.
I've tried setting the USER ID attribute to the account I want proxying for me, set the PROXY USER ID attribute the same way as well as also tried "/", set the DATA SOURCE attribute to the TNS alias.
This program will be deployed to four different environments that have the same TNS alias in them but point to different servers. So I really need to be able to specify the TNS alias.
Currently I am trying to understand how can two databases communicate to each other (for instance: get data from one to another).
Detailed description
I have two Oracle databases, one on Windows and latter on Oracle VirtualBox. On Windows DB I have one user (PAI) with single table called TESTME. On VirtualBox, only user (PAI_VB) was created. Now, I want to display the content of the TESTME table from SQL Developer from VB.
I have done
I want to display table TESTME using LINK statement:
CREATE DATABASE LINK LINK_TO_PAI
CONNECT TO PAI IDENTIFIED BY PAI
USING 'DESCRIPTION = (ADDRESS=(PROTOCOL=TCP)(HOST=myIP)(PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=XE))';
Note: data from 'DESCRIPTION' section were taken from tnsname.ora file on Windows.
Having that, via following query I will manage to display table:
SELECT * FROM PAI.TESTME#LINK_TO_PAI;
Unfortunately, it does not work.
Error from console
ORA-12154: TNS:could not resolve the connect identifier specified
12154. 00000 - "TNS:could not resolve the connect identifier specified"
*Cause: A connection to a database or other service was requested using
a connect identifier, and the connect identifier specified could not
be resolved into a connect descriptor using one of the naming methods
configured. For example, if the type of connect identifier used was a
net service name then the net service name could not be found in a
naming method repository, or the repository could not be
located or reached.
*Action:
- If you are using local naming (TNSNAMES.ORA file):
- Make sure that "TNSNAMES" is listed as one of the values of the
NAMES.DIRECTORY_PATH parameter in the Oracle Net profile
Questions
Could you please propose solution to my problem (I know that in *Action section there is a hint but still I cannot solve it).
Maybe, you could introduce me another way to make communication between two databases possible.
EDIT
I managed to connect from my VB machine to one on Win10 via SQLDeveloper and SQLPlus. Unfortunately, using Oracle LINK I can not access data from database.
SOLVED !!
I managed to solve my issue. The problem laid in LINK. Since following part:
'DESCRIPTION = (ADDRESS=(PROTOCOL=TCP)(HOST=myIP)(PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=XE))'
was inside tnsnames.ora file i should define my link as follows:
CREATE DATABASE LINK LINK_TO_PAI
CONNECT TO PAI IDENTIFIED BY PAI
USING 'xe';
After that minor change, I was able to freely us LINK in my example. Cheers :)
Here's what you need to have for a working database link:
Network connectivity between the two hosts.
Oracle Listener process running on the host you want to connect to.
Correct TNS entry while creating the link.
Correct username and password to connect to the remote database.
The TNS-12154 error you're getting means the database running on the virtual host can't get to XE's listener using the description you gave it.
Make sure you're using the correct IP address when trying to connect to your Windows host from your virtual machine.
Run tnsping from your virtual environment to see if it can get to the Windows host listener.
tnsping 'DESCRIPTION = (ADDRESS=(PROTOCOL=TCP)(HOST=your_windows_host_ip_from_step_1)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE))'
or just tnsping XE if you have the TNS entry stored as XE in tnsnames.ora file on your virtual machine.
See also: Oracle documentation — Testing Connections.
Once you get OK response from tnsping try connecting to XE with sqlplus (sqlplus PAI/PAI#XE) or via SQL Developer running on the virtual host. If you can connect that way your database link should also work with the same TNS entry.
This is a tricky part of oracle because there are a number of diverent ways to make a connection.
I suggest that you begin to make sure that you have a tnsnames.ora file both on windows and in your virtualbox environment. What os are you running in VirtualBox by the way?
In both tnsnames.ora files both databases should be named. Easiest to make them identical.
Then connect with sql*plus from windows to your database in VirtualBox and from VirtualBox to your database on Windows.
Just to make sure your network and tns config are OK.
If this works recreate your db-link with the servce alias from tnsnames after using. This should work.
I have installed Oracle on Ubuntu with OS user oracle. When I try to connect to Oracle when logged on as different OS user (other than oracle), I get error:
SQL> connect user1/user1#orcl
ORA-12154: TNS:could not resolve the connect identifier specified
However, if I don't mention Oracle SID then I don't get any error:
SQL> connect user1/user1
Connected to:
Oracle Database
SQL>
I have declared ORACLE_HOME and SID in the user profile. But it did not work. Can someone please help me to understand the issue.
In a sense you don't really have a problem; you can connect locally using the ORACLE_HOME and ORACLE_SID environment variables, which is fine.
When you use the connect user1/user1#orcl version, the orcl is not your SID; as explained in the documentation it is an 'Oracle Net connect identifier'.
connect_identifier
An Oracle Net connect identifier. The exact syntax depends on the
Oracle Net configuration. For more information, refer to the Oracle
Net manual or contact your DBA. SQL*Plus does not prompt for a service
name, but uses your default database if you do not include a connect
identifier.
So you are connecting over a network connection, even though its to the same host, rather than internally using IPC. You don't even need to have ORACLE_SID set when you do that, because that is used for IPC and isn't part of the network connection.
Now, the connect identifier may well actually be the same string as your SID, but it doesn't have to be. Usually when you're using a single term like orcl you're using a 'net service name' which is defined in your tnsnames.ora file. (Depending on how the naming methods are configured in your sqlnet.ora, which determines how the connect identifier is resolved; but this is still the most common configuration I think).
The Oracle Net configuration can be configured using the netca configuration assistant, as the oracle user, though you can create a private tnsnames.ora to override that.
See the Oracle Net admin guide for more about how connectivity works and is configured, and the SQL*Plus user guide for a shorter version.
In order for your user1/user1#orcl connection to work you would need a tnsnames.ora entry looking something like:
orcl =
(DESCRIPTION =
(ADDRESS = (PROTOCOL=tcp)(HOST=my_host)(PORT=1521))
(CONNECT_DATA = (SERVICE_NAME = orcl)))
... where my_host is the DNS name or IP address of your Oracle server, and 1521 is the port the listener is configured to run on. (The listener has to be running for you to be able to connect this way, too). The SERVICE_NAME is not necessarily the same as your SID either, but depends on the database configuration; the lsnrctl status command will show what service names are available.
The ORA-12154 error is telling you that you either don't have a tnsnames.ora file at all, or that it doesn't contain an entry for the alias orcl.
As #a_horse_with_no_name points out, there are other forms of connect identifier, and you don't necessarily need a tnsnames.ora file for a network connection; the options are explained here. I've just focused on the one you were trying to use. You don't necessarily need to use any of them though since you are able to connect locally.
I have a program that wants to make a connection to an oracle database on our network. This program is written in java and has to use jdbc. Our PC's are setup to use sqlnet.ora files to determine the order of how to resolve. All our PC's first check ldap (which the ldap file is on all these PC's pointing to the ldap server) and then secondly to use tnsnames.ora file, but this file is empty now so basically I want to use ldap, but do it via sqlnet.ora. Any ideas what the connection would look like for the url parameter?
From the JDBC Developer's Guide
The oracle.net.tns_admin system property must be set to the location of the tnsnames.ora file so that the JDBC Thin driver can locate the tnsnames.ora file. For example:
System.setProperty("oracle.net.tns_admin", "c:\\Temp");
String url = "jdbc:oracle:thin:#tns_entry";
DriverManager.getConnection(url, ...);
Because of the system property, the thin driver is able to locate the tnsnames.ora file and thus can resolve the TNS name specified in the URL. Because the thin driver is usually intended to work without an Oracle client installation, this is not enabled by default.
As far as I remember, you only need tnsnames.ora, you don't need an Oracle client when using the thin driver even when specifying a TNS name.
If your program does not allow setting system properties you have two options:
Specify it when starting your program java -Doracle.net.tns_admin=c:/foobar ...
Set an environment variable JAVA_TOOLS_OPTIONS that contains -Doracle.net.tns_admin=c:/foobar. That will then be picked up by any Java program automtically
From the Oracle JDBC FAQ
jdbc:oracle:oci:#<<TNS alias>>
where <<TNS alias>> is the LDAP entry that you would use if you were connecting via, say, SQL*Plus
I'm trying to access an Oracle database on an old server we inherited for a client.
I'm confident I have the Oracle database and listener started and working, but when trying to access sqlplus or the exp commands, I'm getting the following error:
ORA-12162: TNS:net service name is incorrectly specified
I have edited the tnsnames.ora file to change the host to 127.0.0.1 rather than an external URL and I am able to successfully tnsping my connection, but am not getting much further.
Try setting the Oracle SID
set ORACLE_SID=database name
export ORACLE_SID=bvteng worked for me, where bvteng was the service name.
Are you trying a local connection (e.g. "sqlplus u/p") or a network connection (e.g. "sqlplus u/p#pnews10s.world")? Are they both giving you the same error?
The TNSPING by definition is using a network connection. I see some references that indicate you can get the 12612 error when using a local connection. So that is a possible explanation why you are seeing the error from SQLPlus but not TNSPING. If so, try doing a network connection instead.
The local connection not working is probably due to ORACLE_SID not being set correctly as John suggested, but his syntax may not be the right method for whatever shell you are using. Make sure you are using the correct method for the given shell, such as "export ORACLE_SID=name" or "setenv ORACLE_SID name".
I have edited the tnsnames.ora file to change the host to 127.0.0.1 rather
than an external url and am able to successfully tnsping my connection, but am not getting much further.
The last time that happened to me (tnsping works but sqlplus does not, same error message you got), the issue was that someone had copied the tnsnames.ora file from a Windows machine, and left the wrong line feed codes in.
If that is the case, you need to do some dos2unix.
These files are very sensitive to "correct" white-space and tabbing.
Someone should complain to Oracle about that.
Dave Costa has presented you with 2 important question. Are you trying to connect via net8 or locally via extproc? Is the listener on the local machine(127.0.0.1 -- loop back device) setup for extproc connection?
To use the net8 or tcp connection protocol, you need to specify user/pw#tns_alias. To connect locally via extproc you should specify the oracle_sid parameter and then connect via name/pw.
I also notice the tnsalias has the .world domain appended to it, but the sqlnet.ora file does not contain a reference to NAMES.DEFAULT_DOMAIN as being "world".
Also what is the env parameter for TNS_ADMIN? Make sure your tools are looking at the correct tnsnames.ora file. Too many time people modify one tnsnames.ora and the programs/software is looking at another.
Check the tnsnames.ora file, in my case, took me days to find out there were either tab characters in the connection string or other invisible special characters that were causing it to fail.
In my case, the problem was that the DSN and the ServiceName was configured as the same in the odbc.ini file.This should not be a problem, but only after changing the DSN name, I was able to connect to the database through isql.