OCCI app crashes when running in debug mode in Visual Studio 2005

萝らか妹 提交于 2019-12-25 06:22:26

问题


I'm attempting to get a development environment up and running for developing applications with Oracle C++ Call Interface (OCCI) in Visual Studio 2005.

My system specs are: OS: Windows 7, 64-bit Oracle: 11g release 11.2.0.2, 32-bit Instant Client: BasicLite and SDK version 11.2.0.4 32-bit Visual Studio 2005 Professional Edition version 8.0 with 32-bit tools enabled

I've followed this guide by Mark Williams and I got the example running but only in release mode. When I switch to debug mode the app will build, but when I run it I get the following error:

Problem signature:
Problem Event Name: APPCRASH
Application Name:   OCCITest.exe
Application Version:    0.0.0.0
Application Timestamp:  53f5dfdd
Fault Module Name:  KERNELBASE.dll
Fault Module Version:   6.1.7601.18229

The small example program that triggers this error is:

#include "employees.h"

using namespace std; 
using namespace oracle::occi;

int main (void) 
{ 
  Employees *pEmployees = new Employees();
  delete pEmployees;
  return 0; 
}

Employees::Employees() 
{      
  user = "hr"; 
  passwd = "hr"; 
  db = "localhost:1521/service_name";
  env = Environment::createEnvironment(Environment::DEFAULT);

  try 
  { 
    con = env->createConnection(user, passwd, db); 
  } 
  catch (SQLException& ex) 
  { 
    cout << ex.getMessage();
    exit(EXIT_FAILURE); 
  } 
}

Employees::~Employees() 
{ 
  env->terminateConnection (con);
  Environment::terminateEnvironment (env); 
}

If I remove all calls to OCCI functionality the application doesn’t crash. That is, this program runs error-free:

#include "employees.h"

using namespace std; 
using namespace oracle::occi;

int main (void) 
{ 
  Employees *pEmployees = new Employees();
  delete pEmployees;
  return 0; 
}

Employees::Employees() 
{ 
  user = "hr"; 
  passwd = "hr"; 
  db = "localhost:1521/service_name";
  cout<<"Look at me, I'm running"<<endl;
}

Employees::~Employees() 
{}

In the guide Mark mentions that when running in debug mode, the linker should use the library file oraocci11d.lib. However, this file is not included in the Instant Client SDK version 11.2.0.4, so I’m using the input file oraocci11.lib for both the release and debug version.

I'm running out of ideas about how to proceed in solving this problem, and I would greatly appreciate any and all help.


回答1:


If the Oracle DLL receives and/or passes objects such as std::string or any other object that either:

  1. Manipulates the heap in any way, or
  2. The objects could have differing internals between app and DLL,

then you have no choice but to use the correct library to link with. Otherwise you wind up with binary or heap incompatible objects being passed, which leads to what you're seeing now.

See here: http://docs.oracle.com/cd/E11882_01/appdev.112/e10764/install.htm#CBHGBBJI

The link above mentions both the debug import library and debug version of the DLL. Also this is stated at the link:

Applications that link to MSVCRTD.DLL, a debug version of Microsoft C-Runtime, /MDd compiler flag, should link with these specific OCCI libraries: oraocci11d.lib and oraocci11d.dll.




回答2:


Since it took me quite some time to get the debug environment working I figured I'd answer my own question now that I did.

I got a variety of errors throughout the ordeal, but the error that I got most stuck on was an error saying:

'The application was unable to start correctly (0xc0150002). Click OK to close the application.'

Also, I used http://www.dependencywalker.com which repeatedly told me that either oraocci11d.dll or a the following list of dll's could not be found.

API-MS-WIN-APPMODEL-RUNTIME-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL 
API-MS-WIN-CORE-WINRT-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL
API-MS-WIN-SHCORE-SCALING-L1-1-1.DLL
DCOMP.DLL
IESHIMS.DLL

However, what was really missing was for the executable to be able to find oci.dll. I'm just mentioning the errors in case someone else runs into these.

Here is what was needed to make it work:

First of all, the Instant Client does not contain the oraocci11d.lib or oraocci11d.dll, so it is necessary to install the full Oracle Client.

Next, the following must be added to the PATH:

  • C:\Program Files\Oracle\11.2.0\OCI\lib\MSVC\vc8
  • C:\Program Files\Oracle\11.2.0\BIN

In Visual Studio, select Tools -> Options, unfold 'Projects and Solutions' and select VC++ Directories. In 'Show directories for' under:

  • Include Files add C:\Program Files\Oracle\11.2.0\OCI\include
  • Library files add C:\Program Files\Oracle\11.2.0\OCI\lib\MSVC\vc8

In the property page for your project under Configuration Properties -> Linker select Input and under Additional Dependencies add oraocci11d.lib (or oraocci11.lib for release mode). Then select debug/release mode in the Configuration Manager




回答3:


I have a related problem in that I am successfully using oraocci12d.dll/msvcr100d.dll, but this in turn is using oci.dll/msvcr100.dll. ie, oci.dll is not using the debug version of msvcr100.

My program seems to run okay, but any memory leak reporting disappears on exit.



来源:https://stackoverflow.com/questions/25429842/occi-app-crashes-when-running-in-debug-mode-in-visual-studio-2005

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!