Orable DB and MVC 4 - Connection Error (ORA-06413)

2

I have a dll that is responsible for performing queries in the database. In this dll , in the connection class, I have a method that opens the connection to the database and returns the connection, as seen below:

private OracleConnection _IniciarConexao()
{
    ///Limpa as variáveis de erro
    this.UltimaExcecao = null;
    this.Erros         = new List<Exception>();

    OracleConnection conexao = null;

    try
    {
        conexao = new OracleConnection("Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=***)(PORT=***)))(CONNECT_DATA=(SERVICE_NAME=****)(SERVER = DEDICATED))); User Id=***; Password=***;");

        conexao.Open();
    }
    catch (Exception ex)
    {
        this.UltimaExcecao = ex;
        this.Erros.Add(ex);
    }

    return conexao;
}

The dll used for Oracle references is System.Data.OracleClient.dll Versão 2.0.50727 .

This dll is consumed by a Web application using MVC 4 with C# and .Net Framework 4.0 .

When I use this dll in a Windows Forms project I get connection to the database without problems, however when I use a MVC or WebForms system, a connection error with the database occurs.

The error that occurs is ORA-06413 . The image below can illustrate what happened:

I'm already on the second day of unsuccessful research on how to solve this problem.

When publishing the system to the production server, it is able to connect normally, but in place, to use debug mode, I can not connect to the database.

Does anyone know how to fix this error, or some source that can tell me to solve this problem?

    
asked by anonymous 13.10.2015 / 15:41

4 answers

4

This error is commonly caused by incompatibility of architectures between the Oracle DLL and the application that is running. If you are using the 64bit version of the DLL, for example, in Web projects, you must configure the IIS Application Pool to use 64bit or enable IIS Express configuration in Visual Studio, if applicable:

  • If you are using IIS , by default it runs as 64bit. If you need to force 32bit, within IIS Manager, expand "Application Pools", locate the Pool that your application is using, right click > Advanced Settings:

Ifthe"Enable 32-Bit Applications" setting is set to True , the pool will run as 32bit, otherwise 64bit.

  • If you are using IIS Express , within Visual Studio, go to TOOLS > Options > Projects And Solutions > Web Projects > and check the checkbox "Use the 64 bit version of IIS Express for web sites and projects":

    
13.10.2015 / 16:29
1

Adding the DLL directly can be a problem, especially considering that there may be a change in environments when publishing your application.

Instead of adding the DLL directly, use the official NuGet package for Oracle drivers :

PM> Install-Package Oracle.ManagedDataAccess
    
13.10.2015 / 16:06
1

I think I found the problem.

I was testing a project that was a console application, using an Oracle database access dll identical to the problem. The .csproj file was set up as below:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
 <DebugSymbols>true</DebugSymbols>
 <DebugType>full</DebugType>
 <Optimize>false</Optimize>
 <OutputPath>bin\Debug\</OutputPath>
 <DefineConstants>TRACE;DEBUG</DefineConstants>
 <ErrorReport>prompt</ErrorReport>
 <WarningLevel>4</WarningLevel>
 <PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

However, when I went to search the .csproj file for my console application, it looked like this:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
 <DebugType>pdbonly</DebugType>
 <Optimize>true</Optimize>
 <OutputPath>bin\Release\</OutputPath>
 <DefineConstants>TRACE</DefineConstants>
 <ErrorReport>prompt</ErrorReport>
 <WarningLevel>4</WarningLevel>
 <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>

The solution was to copy this section of the .csproj from the dll, replacing the .csproj snippet from my console application with the dll snippet. After the replacement the problem was solved. I believe that VS2015 was getting lost when it saved the dlls to be used, saving one part in the bin / Release folder and another in the bin / Debug folder.

    
05.12.2017 / 18:18
1

The answer from @MarcusVinicius solved my problem for web projects, but I still had a problem with desktop applications such as windows forms and console aplication .

Looking at the @HendrigWernner answer I noticed the <Prefer32Bit>false</Prefer32Bit> tag. I looked at the project properties and unselected this option in the project properties, on the build tab.

Making this modification the project worked correctly and the connection error no longer appeared.

    
15.12.2017 / 14:11