I'm kinda new to using database. I've been learning oracle sql and have installed oracle express edition 18c from their site. I generally perform sql queries through the provided SQL*Plus tool. Now, i really want to be able to connect to the database from my c++ program for a project. I heard about odbc and I went and downloaded the odbc drivers and instant client for my oracle version from their site. Then i found a 3rd party library called SQLAPI++ which can be used to connect to the database with c++. I downloaded and included the library in my project. I'm using codeblocks IDE on windows 10. I tried to run this program to test whether i can connect to the database-
#include<iostream>
#include<SQLAPI.h>
using namespace std;
int main()
{
SAConnection conn;
try
{
conn.Connect("Data Source=LIBRARY;User Id=my_uid;Password=my_pass;Integrated Security=no","my_uid","my_pass",SA_Oracle_Client);
//LIBRARY is my dsn that i created by using the odbc 64-bit admin. tool in the user dsn tab. I used the "Oracle in instantclient_18_5" driver for it.
if(conn.isConnected()==TRUE)
{
cout<<"Connected successfully"<<endl;
conn.Disconnect();
cout<<"Disconnected successfully"<<endl;
}
else
cout<<"Failed to connect"<<endl;
}
catch(SAException &a)
{
cout<<endl<<a.ErrText().GetMultiByteChars()<<endl;
}
}
There are no compiler errors or warnings. Now it prints--"ORA-12154: TNS:could not resolve the connect identifier specified". Any help would be greatly appreciated! >.<
Edit: Now that i run the debugger, this is what i see-
Setting breakpoints
Debugger name and version: GNU gdb (GDB) 7.9.1
Child process PID: 15224
In __cxa_throw () ()
1094 oraAPI.cpp: No such file or directory.
#1 0x00494eb2 in oraAPI::Check (this=0x1307fe8, sCommandText=..., status=-1, hndlp=0x95f208, type=2, pOCIStmt=0x0) at oraAPI.cpp:1094
In __cxa_get_globals () ()
#3 0x00494c06 in oraAPI::Check (this=0x1307fe8, status=-1, hndlp=0x95f208, type=2, pOCIStmt=0x0) at oraAPI.cpp:1018
1018 in oraAPI.cpp
Cannot open file: ../../../../../src/gcc-5.1.0/libgcc/unwind-sjlj.c
At ../../../../../src/gcc-5.1.0/libgcc/unwind-sjlj.c:126
Cannot open file: ../../../../../src/gcc-5.1.0/libgcc/unwind-sjlj.c
At ../../../../../src/gcc-5.1.0/libgcc/unwind-sjlj.c:128
In __cxa_get_globals () ()
1730 SQLAPI.cpp: No such file or directory.
#7 0x004054bb in SAConnection::NativeAPI (this=0x5710b2 <__DTOR_LIST__+306>) at SQLAPI.cpp:1730
In __cxa_throw () ()
1018 oraAPI.cpp: No such file or directory.
#2 0x00494c06 in oraAPI::Check (this=0x1307fe8, status=-1, hndlp=0x95f208, type=2, pOCIStmt=0x0) at oraAPI.cpp:1018
[Inferior 1 (process 15224) exited normally]
Debugger finished with status 0
I know I'm a total noob at this but i'll post what worked for me anyway. I didn't manage to use odbc to connect to my oracle 18c database in the end but occi did the trick. I used SA_Oracle_Client as the 4th parameter and "host_name:port_no/service_name" as the connect string(1st parameter). These values i just copied from the tnsnames.ora file. Before this, i had to setup the environment variable, TNS_ADMIN to point to the directory of tnsnames.ora in the oracle_home installation folder and install the 32-bit instantclient since my compiler is 32-bit but my system, oracle installation and the previous instantclient i had downloaded were all 64-bit. Thanks to all who helped :)