This discussion is archived
4 Replies Latest reply: Apr 20, 2012 2:09 AM by kmohan RSS

Сpp GCC Oracle Connection

931292 Newbie
Currently Being Moderated
Hello. I am trying to connect to my Oracle DB from C++.

I has installed

instantclient-basic-linux

instantclient-basiclite

instantclient-jdbc-linux

instantclient-sqlplus-linux

instantclient-sdk-linux

instantclient-odbc-linux

instantclient-tools-linux

I know that is not necessary, but I have no Idea, why it doesn't work

I Have done

export ORACLE_BASE=/usr/lib/oracle

export ORACLE_HOME=$ORACLE_BASE/11.2/client64

export LD_LIBRARY_PATH=$ORACLE_HOME/lib

export PATH=$ORACLE_HOME/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:~/bin

[root@gerrard ~]# echo "/usr/lib/oracle/11.1/client/lib"; > /etc/ld.so.conf.d/oic.conf

[root@gerrard ~]# /sbin/ldconfig

I Have got a very simple program.
<code>#include <occi.h>
#include <iostream>
#include <iomanip>

#define db_user_name "hr"
#define db_password "hr"
#define db_conn_str "192.168.56.101:1521/@XE"
//#define db_conn_str "system"
using namespace oracle::occi;
using namespace std;

int main(){
try{
Environment* env = Environment::createEnvironment(Environment::OBJECT);
Connection* conn = env->createConnection(db_user_name, db_password, db_conn_str);
cout<<<font color="#A31515">"HELLO";
Statement* stmt = conn->createStatement("Select 1 from dual");
ResultSet *rs = stmt->executeQuery();
int res = 0;
while (rs->next())
{
res = rs->getInt(1);
}

stmt->closeResultSet(rs);
env->terminateConnection(conn);
Environment::terminateEnvironment(env);
}
catch(SQLException &sqlExcp)
{
cerr << sqlExcp.getErrorCode() << <font color="#A31515">" " << sqlExcp.getMessage() << endl;
  }
  <font color="#0000ff">return 0;
}
* This source code was highlighted with Source Code Highlighter.</code>

I compile it with

g++ -o test test.cpp -I /usr/include/oracle/11.2/client64 -L /usr/lib/oracle/11.2/client64/lib/ -lclntsh -locci

And I Get ERROR in OUTPUT


alex@linux-86vr:/media/Files/Media/Programming/Cpp/GCC/BDORACLE> ./test 12514 ORA-12514: TNS:listener does not currently know of service requested in connect descriptor


Google told me that i have to find some tnsnames in my Instant Client. But I have Just

/usr/lib/oracle/11.1/client/bin/adrci

/usr/lib/oracle/11.1/client/bin/genezi

/usr/lib/oracle/11.1/client/lib/libclntsh.so.11.1

/usr/lib/oracle/11.1/client/lib/libnnz11.so

/usr/lib/oracle/11.1/client/lib/libocci.so.11.1

/usr/lib/oracle/11.1/client/lib/libociei.so

/usr/lib/oracle/11.1/client/lib/libocijdbc11.so

/usr/lib/oracle/11.1/client/lib/ojdbc5.jar

/usr/lib/oracle/11.1/client/lib/ojdbc6.jar

/usr/include/oracle/11.1/client/nzerror.h

/usr/include/oracle/11.1/client/nzt.h

/usr/include/oracle/11.1/client/occi.h

/usr/include/oracle/11.1/client/occiAQ.h

/usr/include/oracle/11.1/client/occiCommon.h

/usr/include/oracle/11.1/client/occiControl.h

/usr/include/oracle/11.1/client/occiData.h

/usr/include/oracle/11.1/client/occiObjects.h

/usr/include/oracle/11.1/client/oci.h

/usr/include/oracle/11.1/client/oci1.h

/usr/include/oracle/11.1/client/oci8dp.h

/usr/include/oracle/11.1/client/ociap.h

/usr/include/oracle/11.1/client/ociapr.h

/usr/include/oracle/11.1/client/ocidef.h

/usr/include/oracle/11.1/client/ocidem.h

/usr/include/oracle/11.1/client/ocidfn.h

/usr/include/oracle/11.1/client/ociextp.h

/usr/include/oracle/11.1/client/ocikpr.h

/usr/include/oracle/11.1/client/ocixmldb.h

/usr/include/oracle/11.1/client/odci.h

/usr/include/oracle/11.1/client/oratypes.h

/usr/include/oracle/11.1/client/ori.h

/usr/include/oracle/11.1/client/orid.h

/usr/include/oracle/11.1/client/orl.h

/usr/include/oracle/11.1/client/oro.h

/usr/include/oracle/11.1/client/ort.h

/usr/include/oracle/11.1/client/xa.h

/usr/lib/oracle/11.1/client/lib/libclntsh.so

/usr/lib/oracle/11.1/client/lib/libocci.so

/usr/lib/oracle/11.1/client/lib/ottclasses.zip

/usr/share/oracle/11.1/client/cdemo81.c

/usr/share/oracle/11.1/client/demo.mk

/usr/share/oracle/11.1/client/occidemo.sql

/usr/share/oracle/11.1/client/occidemod.sql

/usr/share/oracle/11.1/client/occidml.cpp

/usr/share/oracle/11.1/client/occiobj.cpp

/usr/share/oracle/11.1/client/occiobj.typ

/usr/share/oracle/11.1/client/ott/usr/bin/sqlplus

/usr/lib/oracle/11.1/client/bin/sqlplus

/usr/lib/oracle/11.1/client/lib/glogin.sql

/usr/lib/oracle/11.1/client/lib/libsqlplus.so

/usr/lib/oracle/11.1/client/lib/libsqlplusic.so

Can you help me, how to resolve this problem.
  • 1. Re: Сpp GCC Oracle Connection
    931292 Newbie
    Currently Being Moderated
    I aded
    tnsnames.ora

    *. ora102 =*
    *(DESCRIPTION =*
    *(ADDRESS= (PROTOCOL = TCP)(HOST = 192.168.56.101)(PORT=1521))*
    *)*

    and
    /etc/idbc.ini

    *[ora102]*
    Application Attributes          = T
    Attributes              = W
    BatchAutocommitMode             = IfAllSuccessful
    CloseCursor             = T
    DisableDPM              = F
    DisableMTS              = T
    Driver          = Oracle_ODBC_Driver_in_ora102
    DSN             = ora102
    EXECSchemaOpt           =
    EXECSyntax              = T
    Failover                = T
    FailoverDelay           = 10
    FailoverRetryCount              = 10
    FetchBufferSize         = 64000
    ForceWCHAR              = F
    Lobs            = T
    Longs           = T
    MetadataIdDefault               = F
    QueryTimeout            = T
    ResultSets              = T
    ServerName              = ora102
    SQLGetData extensions           = F
    Translation DLL         =
    Translation Option              = 0
    UserID          = system

    and

    /etc/odbcinst.ini
    *[ODBC]*
    Trace                   = No
    TraceFile               = /tmp/sql.log
    ForceTrace              = No
    Pooling                 = No
    UsageCount              = 2

    *[Oracle_ODBC_Driver_in_ora102]*
    Description             = Oracle 11g XE ODBC driver.
    Driver                  = /usr/lib/oracle/11.2/client64/lib/libsqora.so.11.1
    Setup                   =
    FileUsage               =
    CPTimeout               =
    CPReuse                 =
    UsageCount              = 2

    I have done
    export TNS_ADMIN=/usr/lib/oracle/11.2/client64/lib/
    Inserted in
    +/etc/ld.so.conf+

    */usr/lib/oracle/11.2/client64/lib*

    Done
    ldconfig


    Any Result :-(
  • 2. Re: Сpp GCC Oracle Connection
    kmohan Explorer
    Currently Being Moderated
    I think problem lies here:
    #define db_conn_str "192.168.56.101:1521/@XE"
    Are you sure @XE is your db service name?

    Does the following work?
    sqlplus user/pass@"192.168.56.101:1521/@XE"
  • 3. Re: Сpp GCC Oracle Connection
    931292 Newbie
    Currently Being Moderated
    alex@linux-86vr:~> sqlplus64 hr/hr@192.168.56.101:1521/@XE

    SQLPlus: Release 11.2.0.3.0 Production on Fri Apr 20 10:29:52 2012*

    Copyright (c) 1982, 2011, Oracle.  All rights reserved.

    ERROR:
    ORA-12514: TNS:listener does not currently know of service requested in connect
    descriptor

    Same error;

    I have lsnrctl just on server but
    LSNRCTL> services
    answers me:

    LSNRCTL> services
    Message 1053 not found; No message file for product=network, facility=TNSMessage 1029 not found; No message file for product=network, facility=TNSMessage 1411 not found; No message file for product=network, facility=TNS
    Message 1408 not found; No message file for product=network, facility=TNS
    Message 1412 not found; No message file for product=network, facility=TNS
    Message 1037 not found; No message file for product=network, facility=TNS
    Message 1050 not found; No message file for product=network, facility=TNS
    Message 1411 not found; No message file for product=network, facility=TNS
    Message 1408 not found; No message file for product=network, facility=TNS
    Message 1412 not found; No message file for product=network, facility=TNS
    Message 1417 not found; No message file for product=network, facility=TNS
    Message 1050 not found; No message file for product=network, facility=TNS
    Message 1411 not found; No message file for product=network, facility=TNS
    Message 1408 not found; No message file for product=network, facility=TNS
    Message 1412 not found; No message file for product=network, facility=TNS
    Message 1413 not found; No message file for product=network, facility=TNS
    Message 1050 not found; No message file for product=network, facility=TNS
    Message 1050 not found; No message file for product=network, facility=TNS
    Message 1052 not found; No message file for product=network, facility=TNSLSNRCTL>

    But sql query
    select * from V$SERVICES
    ansvers:
    *3 : XEXDB*
    *4 : XE*
    *1 : SYS$BACKGROUND*
    *2 : SYS$USERS*
  • 4. Re: Сpp GCC Oracle Connection
    kmohan Explorer
    Currently Being Moderated
    I think your service is XE and not @XE.
    Try
    hr/hr@192.168.56.101:1521/XE

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points