03

通过控制面板->管理工具->Event Viewer->Windows Log->Application Logs, 可以看到可以看到是如下错误

“C:Windowsoraocci11d.dll”的激活上下文生成失败。 找不到从属程序集 Microsoft.VC90.DebugCRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8"。 请使用 sxstrace.exe 进行详细诊断。

原因:

1. 没有安装Microsoft.VC90.DebugCRT,processorArchitecture="x86"

2. 使用了DEBUG版本的oraocci11d.lib 和oraocci11d.dll 动态链接库

解决办法

1. 安装Microsoft.VC90.DebugCRT

2. 或者不要使用DEBUG版本的occi 动态链接库

还有一个ResultSet->getString()的内存错误

解决办法:

  • 我用的是VC++2010, 下载与VC++2010对应的OCCI DLL库
  • 并且occi 的版本要和oci.dll版本匹配,否则可能会出现"11g无法定位程序输入点OCIPHeapAllocUc于动态连接库OCI.DLL上"的问题
  • http://www.oracle.com/technetwork/database/occidownloads-083553.html

总之:VC++版本, OCCI DLL版本, OCI DLL版本三者必须一致。

OCCI示例代码

 1 void test() {
 2 
 3 std::string userName = "scott";
 4 std::string password = "tiger";
 5 std::string connectString = "ORCL";
 6 //Environment::createEnvironment("AL32UTF8","UTF8");
 7 oracle::occi::Environment *env = oracle::occi::Environment::createEnvironment("AL32UTF8","UTF8");
 8 {
 9 oracle::occi::Connection *conn = env->createConnection(
10 userName, password, connectString);
11 oracle::occi::Statement *stmt = conn->createStatement(
12 "SELECT DEPTNO, DNAME FROM DEPT");
13 oracle::occi::ResultSet *rs = stmt->executeQuery();
14 while( rs->next() ) {
15     //oracle::occi::Blob b = rs->getBlob(1);
16      int i =rs->getInt(1);
17     std::string dn =rs->getString(2);
18     //std::cout << "Length of BLOB : " << b.length() << std::endl;
19     //std::cout << "dname : " << dname << std::endl;
20     std::cout << "deptno : " << i << std::endl;
21     std::cout << "dname : " << dn << std::endl;
22 }
23 stmt->closeResultSet(rs);
24 conn->terminateStatement(stmt);
25 env->terminateConnection(conn);
26 }
27 
28 oracle::occi::Environment::terminateEnvironment(env);
29 }
原文地址:https://www.cnblogs.com/xzpp/p/3597459.html