how do i generate a tnsnames.ora file to connect to an oracle database

I have installed Oracle 11g, and I can connect as sysman to the Oracle database, but there is no tnsnames.ora file that I can find.

Do I need to generate the tnsnames.ora file myself? If so, where do I place it? If not, how does Oracle generate it for me? If I do need to generate it, what is the appropriate syntax for the file?

5 Answers

You can easily create a tnsnames.ora [text] file. It should be in $ORACLE_HOME/network/admin/ and should look something like this:

 ORATST=
 (description=
   (address_list=
     (address = (protocol = TCP)(host = fu.bar)(port = 1521))
   )
 (connect_data =
   (service_name=oratst)
 )
)

The default directory for a tnsnames.ora file is

/u01/app/oracle/product/<version>/<dbname>/network/admin/tnsnames.ora

Contents:

<alias> = (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = <ip>)(PORT = <port>))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = <dbname>)
    )
  )
  • alias: you can choose this and use it as connection string later on.
  • port: the default is 1521

f your OS is Windows 10, you can find tnsnames.ora file in the following unc path:

C:\app\myAccount\product\11.2.0\dbhome_1\NETWORK\ADMIN

Where myAccount is your Windows account name.


Leave a comment