无法从 C++ 中的 SQLAPI++ 程序连接到我的 Oracle 数据库

Can't connect to my Oracle database from a SQLAPI++ program in C++

我对使用数据库有点陌生。我一直在学习 oracle sql 并从他们的站点安装了 oracle express edition 18c。我通常通过提供的 SQL*Plus 工具执行 sql 查询。现在,我真的希望能够从我的项目的 C++ 程序连接到数据库。我听说过 odbc,于是我去他们的站点下载了适用于我的 oracle 版本的 odbc 驱动程序和即时客户端。然后我找到了一个名为 SQLAPI++ 的第三方库,可用于使用 C++ 连接到数据库。我下载了该库并将其包含在我的项目中。我在 windows 10 上使用代码块 IDE。我尝试 运行 这个程序来测试我是否可以连接到数据库-

#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;
    }
}

没有编译器错误或警告。现在它打印--“ORA-12154:TNS:could 未解析指定的连接标识符”。任何帮助将不胜感激! >.<

编辑:现在我 运行 调试器,这就是我所看到的-

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

我认为您可能缺少特定于 Oracle 用例的参考资料

#include "oraAPI.h"
IsaAPI *pApi = con.NativeAPI();
oraAPI *pNativeAPI = (oraAPI *)pApi;

我知道我在这方面完全是菜鸟,但我会 post 无论如何,我会选择对我有用的东西。我最终没能使用 odbc 连接到我的 oracle 18c 数据库,但 occi 成功了。我使用 SA_Oracle_Client 作为第四个参数,“host_name:port_no/service_name” 作为连接字符串(第一个参数)。我刚刚从 tnsnames.ora 文件中复制了这些值。在此之前,我必须设置环境变量 TNS_ADMIN 以指向 oracle_home 安装文件夹中的 tnsnames.ora 目录并安装 32 位 instantclient,因为我的编译器是 32 位的但是我的系统、oracle 安装和我之前下载的 instantclient 都是 64 位的。感谢所有帮助过的人:)