C ++使用SQLAPI ++库错误连接到数据库

时间:2017-12-21 20:36:41

标签: c++ sql database oracle

我要制作C ++ Console App并与ORACLE数据库连接。我为此目的使用SQLAPI ++,并使用Visual Studio 2017 IDE。

这些是我做的步骤:

  • 在VS 2017中,我在VC ++目录中添加了一个导演E:\mysql\SQLAPI\include;$(IncludePath)
  • 在VS 2017中,我为SQLAPI ++库E:\mysql\SQLAPI\vs2017\lib\sqlapi.lib;%(AdditionalDependencies)
  • 添加了额外的依赖
  • 我将sqlapi.dll文件的路径添加到我的Enviromental PATH变量中,并将sqlapi.dll文件复制到项目主管。

这是我的代码:

#include "stdafx.h"
#include <SQLAPI.h> 
#include <iostream>
#include <stdio.h>

using namespace std;

int main(int argc, char* argv[])
{
    SAConnection con; // create connection object

    try
    {
        // connect to database
        // in this example it is Oracle,
        // but can also be Sybase, Informix, DB2
        // SQLServer, InterBase, SQLBase and ODBC
        con.Connect(
            "NIKOLAYRM_XE",     // database name
            "NIKOLAYRM",   // user name
            "Aa6352410",   // password
            SA_Oracle_Client);

        printf("We are connected!\n");

        // Disconnect is optional
        // autodisconnect will ocur in destructor if needed
        con.Disconnect();

        printf("We are disconnected!\n");
    }
    catch (SAException &x)
    {
        // SAConnection::Rollback()
        // can also throw an exception
        // (if a network error for example),
        // we will be ready
        try
        {
            // on error rollback changes
            con.Rollback();
        }
        catch (SAException &)
        {
        }
        // print error message
        printf("%s\n", (const char*)x.ErrText());
    }
    system("pause");
    return 0;
}

这是错误: enter image description here

0 个答案:

没有答案