c++通过OCCI访问Oracle编程程序错误_CrtIsValidHeapPointer(pUserData)
程序代码:
#define WIN32COMMON
#include <iostream>
#include <occi.h>
using namespace oracle::occi;
using namespace std;
#pragma comment(lib, "oraocci10.lib")int main(void)
{
Environment *env = NULL;
Connection *conn = NULL;
Statement *stmt = NULL;
ResultSet *rs = NULL;
string user;
string passwd;
string db;
user = "ly";
passwd = "a123";
db = ""; try
{
env = Environment::createEnvironment(Environment::OBJECT);
if(env != NULL)
{
conn = env->createConnection (user, passwd, db);
if(conn != NULL)
{
stmt = conn->createStatement("select * from name");
rs = stmt->executeQuery();

while(rs->next())
{
cout << rs->getString(1);
}

stmt->closeResultSet(rs);
} env->terminateConnection(conn);
} Environment::terminateEnvironment(env);
}
catch (SQLException e)
{
 cout << "Error : ";
 cout << e.getMessage() << endl;
}
return 0;
}工具:VC6+sp6
数据库:oracle10gDebug版运行到cout << rs->getString(1);时出问题
错误信息:
  Debug Assertion Failed!
  File:dbgheap.c
  Line: 1044
  Expression:_CrtIsValidHeapPointer(pUserData)Release版可以正常运行。

解决方案 »

  1.   

    改为#pragma comment(lib, "oraocci10d.lib")也同样的错误
      

  2.   

    没人光顾,我自己搞出来了。
    爽呀!!!!
    MSVCPRT.LIB Multithreaded, dynamic link (import library for MSVCRT.DLL) /MD _MT, _DLL 
    加上这个就好了
      

  3.   

    // !! IMPORTANT NOTE ON WIN32 PLATFORMS !!
    // Please note Oracle TAR 2630255:
    // "In this bug the application is linked with (multi-threaded "
    // "debug C run-time library) MSVCRTD.DLL however, oraocci9.dll "
    // is linked with (multi-threaded  non-debug C run-time library) MSVCRT.DLL.
    //
    // The bottom line to fix this if you experience heap assertion errors -
    // add msvcprt.lib to your list of link libraries.
    // In debug builds (e.g. /MDd), a link to msvcprtd.lib occurs, which appears
    // to be the root of the problem.
    // Oracle had about 4-5 tickets opened about this, and it doesn't appear it's
    // been fixed outside this workaround.