Re: Oracle8 : CONNECT to non-default database -> ORA-12154 (Server Error Message)

From: Jamie Schrumpf <hatterasNOSPAM_at_hotbot.com>
Date: 5 Oct 1999 23:50:32 GMT
Message-ID: <7te2s8$lap$1_at_ash.prod.itd.earthlink.net>


In article <7tcpm6$pfd$1_at_nnrp1.deja.com>, alexander.vinokur_at_telrad.co.il says...
>
>Hi,
>
>
>///////////////////////////////////////////////
>1. Error message
>
>I have got the following error message.
>
>//===========================================
>ORA-12154: TNS:could not resolve service name
>
>in "..."
>on line 97 of demo6.pc.
>//===========================================
>
>
>Here is a relevant piece of the code (Pro*C/C++).
>What (and where) is wrong?
>//===========================================
>// file demo6.pc
>void main()
>{
>/* Declare the program host variables. */
> char *username = "aaa";
> char *password = "bbb";
> char *db_name = "ddd";
> char *db_string = "NYNON";
> asciz dynstmt1;
> char dynstmt2[10];
> VARCHAR dynstmt3[80];
>
> [ --- omitted --- ]
>
> EXEC SQL CONNECT :username // Line#97
> IDENTIFIED BY :password
> AT :db_name
> USING :db_string;
> puts("\nConnected to ORACLE.\n");
>
> [ --- omitted --- ]
>
>}
>//===========================================
>
>========================
>== Oracle 8.0.5
>== Prro*C/C++
>== SunOS 5.6
>========================
>
>
>
>///////////////////////////////////////////////
>2. Questions
>
>Here is a a piece from Oracle8 Documentation and my question.
>=========================================
>Pro*C/C++ Precompiler Programmer's Guide
>Release 8.0
>A58233-01
>4. Advanced Pro*C/C++ Applications
>Connecting to Oracle8
>=========================================
>
>###
>### Single Explicit Connections
>###
>### In the following example, you connect to a single non-default
>database at a
>### remote node:
>###
>### /* declare needed host variables */
>### char username[10] = "scott";
>### char password[10] = "tiger";
>### char db_string[20] = "NYNON";
>###
>### /* give the database connection a unique name */
>### EXEC SQL DECLARE DB_NAME DATABASE;
>###
>### /* connect to the non-default database */
>### EXEC SQL CONNECT :username IDENTIFIED BY :password
>### AT DB_NAME USING :db_string;
>###
>### The identifiers in this example serve the following purposes:
>###
>### * The host variables username and password identify a valid
>user.
>### * The host variable db_string contains the Net8 syntax for
>connecting to
>### a non-default database at a remote node.
>
> In the example above db_string == "NYNON".
>
> 1. If db_string value is not arbitrary,
> what is this value connected with?
>
> 2. Is there any connection between
> db_string value (i.e. "NYNON") and the
> tnsnames.ora configuration file?
>
> 2. Is there any connection between
> db_string value (i.e. "NYNON") and another files?
>
> 4. What do I have to do yet
> to use db_string (== ""NYNON", for instance).

It appears that you do not have an entry in the tnsnames.ora file that corresponds to the database with which you are trying to connect. Db_string should be the name of the tnsnames.ora entry which contains the information used to locate the remote db and provide its instance name.

The tnsnames.ora entries are maintained by the Net8EasyConfig client and the entry should look like this:

# D:\ORACLE\ORA81\NETWORK\ADMIN\TNSNAMES.ORA Configuration File:D:\Oracle\Ora81\NETWORK\ADMIN\tnsnames.ora # Generated by Oracle Net8 Assistant

NYNON =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = computer.domain.com)(PORT = 1521))     )
    (CONNECT_DATA =
      (SERVICE_NAME = nynon.world)
    )
  )

Or something like this.

HTH.

-- 
--------------------------------------------------
Jamie Schrumpf
Received on Wed Oct 06 1999 - 01:50:32 CEST

Original text of this message