Showing posts with label tnsnames. Show all posts
Showing posts with label tnsnames. Show all posts

Monday

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

     This error is, often the very first one you get on trying to establish a connection to your database. Simply put, it means that you have named the database you wish to be connected to and Oracle doesn’t know who you are referring to.

     This error is often caused by typos, maybe in your connection string, but possibly in your tnsnames.ora file. It is also possible that the tnsnames.ora file is not accessible or does not even exist. If it does, ensure that it contains the service name you are using; also go over it to make sure it doesn’t have any unpaired parentheses or such.

     Sometimes when you edit your tnsnames.ora file , especially if you copy-paste , some blank characters can be formed. The best solution is to open your tnsnames.ora file in a text editor and fine tune the format.

(tnsnames.ora file resides in path: /home/oracle/network/admin/tnsnames.ora)

Generic formatting should look like this: 

NEWDB =
    ( DESCRIPTION =
    ( ADDRESS = (PROTOCOL = TCP)(HOST = HOST)(PORT = 1521) )
    ( CONNECT_DATA =
         ( SERVER = DEDICATED )
         ( SERVICE_NAME = NEWDB )
      )
  )


If you are working on a large corporate, sometimes your DNS cannot resolve the service name too. Lets say you have a DB with an HACMP configuration. 
dbserver1.corphost , dbserver2.corphost.
Sometimes the connection cannot resolve the naming and DNS. So you better check first with ip connection before further investigation.

Wednesday

What are Listener.ora , Tnsnames.ora , sqlnet.ora files?

What is a Listener.ora File?

The information about this listener can be found in the listener.ora file.
This file is normally found in the $ORACLE_HOME/network/admin folder.
If the file is not here then you can search in /etc folder if you are on a unix server.

If you have RAC then you can find the name of listener in the initdbname.ora file

So the important point you have to remember is that you should compulsorily  have a listener.ora file
if your users have to connect from a different server.

What is a Tnsnames.ora File?
The tnsnames.ora file contains the information about the server where your database is present , the
port number information , the database name , the protocol used (tcp etc ).  If a user wants to
connect to a database then the software program which the user is using will look in the
tnsnames.ora file and find out all the information what we discussed before. Then the software
program uses this information and makes a connection to the database with the help of the listener.

So important point is if a user want to connect to a database he or she would definetly need a
tnsnames.ora file.

What happens if 100 users want to connect to the database? Do we need 100 tnsnames.ora files?
If the users are using a software program that is located on their machine then each user will need his
own tnsnames.ora file. If the users are connecting to a website for example www.google.com then
the user do not need to have a tnsnames.ora on his machine because the website is located on a
webserver so the tnsnames.ora file would already be in the webserver.

Some java programs do not need a tnsnames.ora file .What they do is ,they can read all this
information from a different file which they created . The java developers speak to the dba and will
get the database information. Then they store this information in a different file. Then the java
program reads this file and will connect to the database.


What is sqlnet.ora file ?

If a tnsnames.ora file has to work properly , then we need the sqlnet.ora file. The sqlnet.ora file
contains some information which the user process(the user connection) needs ,to find exactly where
a database server is located. So the user process normally reads the tnsnames.ora file and then the
sqlnet.ora file and thus will find the complete database server information, database name etc and
will talk to the listener which is present on the database server. The listener will then will see that a
conenction is opened to the database.

There are also lot of other parameters in the sqlnet.ora file that you can use.

 For UNIX users, the order in which Oracle searches locations for Oracle Net files like sqlnet.ora and tnsnames.ora are in this order:

1. $HOME for hidden files only (i.e., .sqlnet.ora and .tnsnames.ora)
2. $TNS_ADMIN
3. $HOME
4. /etc or /var/opt/oracle (depends on platform)
5. $ORACLE_HOME/network/admin

For Windows users, the search order is a bit different. It goes like this,
1. current path (associated with the running client application)
2. Environment variable TNS_ADMIN defined for the session
3. Environment variable TNS_ADMIN defined for the system
4. Windows Registry Key TNS_ADMIN
5. %ORACLE_HOME%\network\admin