Доброго времени суток, уже который день бьюсь над совмещением Oracle и C++. через OCCI. instantclient Я поставил, причём все версии
instantclient-basic-linux
instantclient-basiclite
instantclient-jdbc-linux
instantclient-sqlplus-linux
instantclient-sdk-linux
instantclient-odbc-linux
instantclient-tools-linux
Я знаю, что это не надо, но уже не знал в чём проблема.
создал фаил tnsnames.ora,
. ora102 =
(DESCRIPTION =
(ADDRESS= (PROTOCOL = TCP)(HOST = 192.168.56.101)(PORT=1521))
)
прописал путь к оракл либ сюда
/etc/ld.so.conf
выполнил ldconfig
создал файлы
/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
И /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
Выполнил установку переменных.
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
export TNS_ADMIN=/usr/lib/oracle/11.2/client64/
Взял простой пример программы
#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<<"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() << " " << sqlExcp.getMessage() << endl;
}
return 0;
}
компилирую вот так:
g++ -o test test.cpp -I /usr/include/oracle/11.2/client64 -L /usr/lib/oracle/11.2/client64/lib/ -lclntsh -locci
На выходе получаю не прияную Оракловскую ошибку.
12514 ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
Пытаюсь проверить так
isql ora102 hr hr
получаю
[ISQL]ERROR: Could not SQLConnect