miércoles, 16 de julio de 2014

Visual Studio 2010 Express y Oracle Database

Un programa escirto en C++ y complicado en Visual Studio 2010 Express que se conecta a una base de datos Oracle. La infreaestructura

1.- Visual Studio 2010 Express

Ya que mi OS es un Windows 7 de 64 bit me permitio conocer que el Visual Studio 2010 Express crea por defecto solo ejecutables de 32 bit .

Pense, no hay problema uso las librerias de 32 bit, pero al ejecutar mi programa simpre obtenia el siguiente error:

0xc000007b

 En mi investigacion encontre lo siguiente:

"The error code means that the executable image header isn't good (for whatever reason). So... compiled 64 bits and try to run under 32 bits, or defective harddisk would be two possibilities"

"I think that you trying to use 64-bit DLL with 32-bit application (or vice versa)".

"Mainly these native errors are created due too using x32 bit libraries on x64 systems and vice versa or by not configuring your project settings correctly."

En forma de una equacion podria decir que:

 Windows7 (64-bit) + Visual Studio 2010 Express (32-bit) + OCI (32-bit) = 0xc000007b

Cambiar solo la version del OCI a 64-bit no cambio el resultado.

Windows7 (64-bit) + Visual Studio 2010 Express (32-bit) + OCI (64-bit) = 0xc000007b

Fue necesario alterar entonces la otra variable de nuestra equacion.

Compiling a 64-bit Application in Microsoft Visual Studio Express 2010  

Sin embargo, se presento otro error. La instalacion fallaba con el error:

Action start 10:38:35: INSTALL. Action start 10:38:35: DDSE_CA_Uninstall_InstallExecuteSequenceStarts_amd64. 07/16/14 10:38:35 DDSet_Status: LANGID: 1033 07/16/14 10:38:35 DDSet_Entry: ImmediateDispatch: DDSE_CA_Uninstall_InstallExecuteSequenceStarts entry 07/16/14 10:38:35 DDSet_Error: Patch Hooks: Missing required property 'ProductFamily': Setup cannot continue. 07/16/14 10:38:35 DDSet_Warning: Setup failed while calling 'getDLLName'. System error: Cannot create a file when that file already exists. 

Para esto la soucion fue desistalar toda las versiones superiores a 10.0.30319 del Microsoft Visual C++ 2010 x64 Redistributable

"Had a similar problem which turned out to be that the SDK 7.1 does NOT install if you have a newer vcredist_x86.exe than version 10.0.30319 of Visual C++ 2010 x86 Redistributable... I had 10.0.30419 installed... removed it through control panel "remove programs" and then the SDK 7.1 installed." 


Una vez solventado el tema del compilador nuestra ecuacion quedo de la siguiente forma, con un nuevo error:

Windows7 (64-bit) + Visual Studio 2010 Express (64-bit) + OCI (64-bit) = Exception: ORA-24960: the attribute OCI_ATTR_USERNAME is greater than the maxim um allowable length of 255

Para evitar inconsistencias con las librerias cambiela version del cliente OCI a de 12c a 11.2.0.4.
Oracle C++ Call Interface - Downloads

Pero apesar de esto el problema seguia siendo el mismo.

Windows7 (64-bit) + Visual Studio 2010 Express (64-bit) + OCI (64-bit) = Exception: ORA-24960: the attribute OCI_ATTR_USERNAME is greater than the maxim um allowable length of 255

Fue entonces cuando encontre este comenatrio:

carefully , if you are in debug model , use the oraocci10d.lib, not the oraocci10.lib

La soucion fue usar la libreria oraocci10d.lib ya que - segun lo que puedo entender ya que no sou expreto en VS2010- mi Visual Studio 2010 Express esta en modo Debug.

2.- El programa

#include "stdafx.h"
#include
#include  
using namespace std;

namespace oc = oracle::occi;

int main()
{
   try
   {
      // setup
      oc::Environment* env = oc::Environment::createEnvironment(); // 1
 oc::Connection* conn = env->createConnection("SYSTEM", "Oracle4U#", "TEMPFIN"); //2
      oc::Statement* stmt = conn->createStatement("select sysdate from dual"); // 3

      // execution
      oc::ResultSet* res = stmt->executeQuery(); // 4
      while(res->next()) // 5
         //std::cout << res->getString(1) << ' ' << res->getString(2) << ' ' << res->getInt(3) << std::endl;
 std::cout << res->getString(1)  << std::endl;

      // cleanup
      stmt->closeResultSet(res); // 6
      conn->terminateStatement(stmt);
      env->terminateConnection(conn);
      oc::Environment::terminateEnvironment(env);
   }
   catch(const oc::SQLException& e) // 7
   {
      std::cout << "Exception: " << e.what() << std::endl;
   }

   system("pause");
}

 El programa original lo puedes ecnontrar en este link.

3.- Configuracion del VS2010 Express

project -> properties -> C/C++ -> General -> C:\Users\pwjxm51\Downloads\oci11\64\instantclient_11_2\sdk\include; project -> properties -> Linker -> General -> C:\Users\pwjxm51\Downloads\oci11\64\instantclient_11_2\sdk\lib\msvc; C:\Users\pwjxm51\Downloads\oci11\64\instantclient_11_2\sdk\lib\msvc\vc9 project -> properties -> Linker -> Input -> oraocci11d.lib; project -> properties -> Debugging -> C:\Users\pwjxm51\Downloads\oci11\64\instantclient_11_2\sdk\lib\msvc\vc9 

 Finalmente todo funciono y el resultado fue: 

 C:\>Test1.exe 
16-JUL-14 Press any key to continue . . .

1 comentario: