Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2007
    Posts
    8

    Unanswered: Error connecting to Oracle in Pro*C/C++

    I am new to oracle. Hope someone can help me with connecting to Oracle in pro*C/C++ app.

    My connection string is in the format of "user/pwd@service_name".

    I use the statement:

    EXEC SQL CONNECT :connect_string;

    I keep getting error ORA-12154.

    When I use the same connect string with sqlplus, it works.

    Please Help!

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Code:
    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
    //        (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.DIRETORY_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.
    This is really a FAQ.
    SEARCH or GOOGLE will provide many, many hits
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Sep 2007
    Posts
    8
    Thanks for the reply. I did google and found the posting. I followed the steps and checked the ora config files and still have the same problem. Since sqlplus works, so I think the configuration and environment set up is ok.
    Below are the contents of the ora config files:

    sqlnet.ora:
    NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)

    tnsnames.ora:
    vapod1 =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS=
    (PROTOCOL=TCP)
    (HOST=vapd1.devo.ilx.com)
    (PORT=1522)))
    (CONNECT_DATA=(SERVICE_NAME=vapod1)))

    Here is the code I used for connecting:

    EXEC SQL BEGIN DECLARE SECTION;
    VARCHAR connect_string[80];
    EXEC SQL END DECLARE SECTION;

    const char *CONN_STR="tester/tester@vapod1";

    memset(connect_string.arr, '\0', sizeof(connect_string.arr));
    strcpy((char *)connect_string.arr, CONN_STR);
    connect_string.len = strlen((char *)connect_string.arr);
    EXEC SQL WHENEVER SQLERROR GOTO errexit;
    EXEC SQL CONNECT :connect_string;
    ...

    When I ran my program, I got this:
    Error: ORA-12154: TNS:could not resolve the connect identifier specified

    I am able to connect using sqlplus:
    sqlplus tester/tester@vapod1


    I ran "tnsping vapod1", and it is good:

    Used TNSNAMES adapter to resolve the alias
    Attempting to contact (DESCRIPTION= (ADDRESS_LIST= (ADDRESS=(PROTOCOL=TCP)(HOST= vapd1.devo.ilx.com)(PORT=1522))) (CONNECT_DATA = (SERVICE_NAME=VAPOD1)))
    OK (10 msec)

    Is there something wrong with my code? Could any proc options and compiler options cause the problem? I am new to oracle and do not know how to go about debugging this.

    Thanks.

  4. #4
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    post tail end of listener.log file which contains records which show both successful connection from sqlplus & failure from your code.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  5. #5
    Join Date
    Sep 2007
    Posts
    8
    When I ran sqlplus, I saw the entry for sqlplus connecting in listener.log.

    But when I ran my little program, I got the ora-12154 error right away and did not see any entry in listener.log.

    Am I linking correctly? I just used the makefile from demo.

    CC -mt -c -I. -I/ilx/oracle/product/10.2.0/client_1/precomp/public32 -I/ilx/oracle/product/10.2.0/client_1/precomp/public -I/ilx/oracle/product/10.2.0/client_1/rdbms/public -I/ilx/oracle/product/10.2.0/client_1/rdbms/demo -I/ilx/oracle/product/10.2.0/client_1/plsql/public -I/ilx/oracle/product/10.2.0/client_1/network/public cppdemo1.c
    CC -mt -o cppdemo1 cppdemo1.o -L/ilx/oracle/product/10.2.0/client_1/lib32/ -lclntsh `cat /ilx/oracle/product/10.2.0/client_1/lib32/ldflags` `cat /ilx/oracle/product/10.2.0/client_1/lib32/sysliblist` -R/ilx/oracle/product/10.2.0/client_1/lib32 -laio -lposix4 -lm

    Thanks

  6. #6
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    ORA-12154 implies the listener got the request but could not satisfy the request because it did not know about SID or SERVICE requested.
    Listener logs every request.

    Indications are that the request is getting to some listener.
    Can you locate the listener & listener.log?
    You may need to employ a network sniffer to determine what really happens.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  7. #7
    Join Date
    Sep 2007
    Posts
    8
    I run 'ps -ef | grep tnslsnr' and see only one tnslsnr running on the server machine.
    oracle 3766 1 0 Jul 01 ? 4:19 /ilx/oracle/product/10.2.0/db_1/bin/tnslsnr LISTENER -inherit

    I found the listener.log in the $ORACLE_HOME/network/log directory on the server.


    Thanks

  8. #8
    Join Date
    Sep 2007
    Posts
    8
    Finally got the solution from Oracle tech support. I was using 10.2.0.1 32-bit library client library, which has the connection problem. I was told to use 10.2.0.4, and it works fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •