1、先前用occi操作oracle数据库都是失败,后来发现是我下载的库版本和对应的dll版本不一致导致:如32库, 却下载了64位的dll,因此导致在初始化环境就失败,百思不得其解。
2、在下载好对应的32位库和32位dll,可以正常初始化环境,操作oracle数据库。
3、只需下载2个文件,其他版本的文件根据自己需要下载。如我下载的是:instantclient-basic-nt-11.2.0.3.0.zip 和 instantclient-sdk-nt-11.2.0.4.0.zip
4、我下载的文件只支持vs2005和vs2008
5、发现运行正常,无需在安装或配置oracle数据库驱动等。
6、运行时依赖的库有:针对我这次运行例子:oci.dll、oraocci11.dll、oraociei11.dll
7、dll可以在instantclient-basic-nt-11.2.0.3.0.zip 找到,
8、程序依赖的头文件、库文件可以在instantclient-sdk-nt-11.2.0.4.0.zip找到
9、依赖的头文件位于instantclient-sdk-nt-11.2.0.4.0.zip文件夹中的include文件夹
10、依赖的库文件位于instantclient-sdk-nt-11.2.0.4.0.zip文件夹中的msvc文件夹,只用2个库文件:oci.lib 和 oraocci11.lib
附上测试代码:
#include <iostream>
#define WIN32COMMON //避免函数重定义错误
#include <occi.h>
using namespace std;
using namespace oracle::occi;
int main()
{
//创建OCCI上下文环境
Environment *env = Environment::createEnvironment();
if (NULL == env) {
printf("createEnvironment error.\n");
return -1;
}
else
cout << "success" << endl;
string name = "用户名";
string pass = "密码";
string srvName = "数据库地址/数据库名";//数据库地址与数据库名之间用“/”分隔
try
{
//创建数据库连接
Connection *conn = env->createConnection(name, pass, srvName);//用户名,密码,数据库名
if(NULL == conn) {
printf("createConnection error.\n");
return -1;
}
else{
cout << "conn success" << endl;
}
//关闭连接
env->terminateConnection(conn);
}
catch (SQLException e)
{
cout << e.what() << endl;
system("pause");
return -1;
}
// 释放OCCI上下文环境
Environment::terminateEnvironment(env);
cout << "end!" << endl;
system("pause");
return 0;
}