我对使用数据库有点陌生。我一直在学习oraclesql,并在他们的网站上安装了oraclexpressedition18c。我通常通过提供的sql*Plus工具执行sql查询。现在,我真的很想能够从我的c++程序连接到一个项目的数据库。我听说了odbc,于是从他们的网站上下载了odbc驱动程序和oracle版本的即时客户端。然后我发现了一个第三方库,名为SQLAPI++,可以用来用c++连接到数据库。我下载了这个库并将其包含在我的项目中。我在Windows10上使用代码块IDE。我试着运行这个程序来测试我是否可以连接到数据库-
#include
#include
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<
conn.Disconnect();
cout<
}
else
cout<
}
catch(SAException &a)
{
cout<
}
}
没有编译器错误或警告。现在它打印出--“ORA-12154:TNS:无法解析指定的连接标识符”。任何帮助都将不胜感激!><
编辑:现在我运行了调试器,这就是我看到的-
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__>) 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