c ++程序中的数据库连接检查

时间:2017-08-03 12:38:56

标签: c++ database visual-studio ocilib

我正在尝试使用OCILIB接口将数据库与c ++程序连接。  我的计划是: -

  #include "ocilib.h"
 int main(int argc, char *args[])
 {
OCI_Connection *cn;
if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT))
    cout << "connection failed";
cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
if (cn != NULL)
{

    cout <<OCI_GetVersionServer(cn);
    cout <<"Server major version : %i\n"<< OCI_GetServerMajorVersion(cn);
    cout <<"Server minor version : %i\n"<<OCI_GetServerMinorVersion(cn);
    cout <<"Server revision version : %i\n"<< OCI_GetServerRevisionVersion(cn);
    cout <<"Connection version : %i\n"<< OCI_GetVersionConnection(cn);

    OCI_ConnectionFree(cn);
}
OCI_Cleanup();

 }

此代码在MSVisualstudio2015中运行,我下载了所有OCI包并根据我的环境进行设置.. 我将链接器路径和其他包含头文件放在项目属性中。 但是当我构建它所显示的应用程序时。

1>------ Build started: Project: Testdatabase, Configuration: Debug x64 ------
1>  Testing.cpp
1>Testing.obj : error LNK2019: unresolved external symbol OCI_Initialize 
 referenced in function main

1>Testing.obj : error LNK2019: unresolved external symbol OCI_Cleanup 
  referenced in function main

 1>Testing.obj : error LNK2019: unresolved external symbol 
 OCI_ConnectionCreate referenced in function main

 1>Testing.obj : error LNK2019: unresolved external symbol 
 OCI_ConnectionFree referenced in function main

 1>Testing.obj : error LNK2019: unresolved external symbol 
 OCI_GetVersionServer referenced in function main

 1>Testing.obj : error LNK2019: unresolved external symbol 
 OCI_GetServerMajorVersion referenced in function main

 1>Testing.obj : error LNK2019: unresolved external symbol 
 OCI_GetServerMinorVersion referenced in function main

 1>Testing.obj : error LNK2019: unresolved external symbol 
 OCI_GetServerRevisionVersion referenced in function main

 1>Testing.obj : error LNK2019: unresolved external symbol 
 OCI_GetVersionConnection referenced in function main

 1>c:\XXXXX\XXXXXX\documents\visual studio 
 2015\Projects\Testdatabase\x64\Debug\Testdatabase.exe : fatal error 
 LNK1120: 9 unresolved externals
 ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我读了一些关于这个问题的文件,但我无法解决这个问题,给我任何解决方案..

1 个答案:

答案 0 :(得分:1)

您需要将ociliba.dll从ocilib存档(在lib32 | 64文件夹下)复制到生成可执行文件的文件夹中。