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

Asked

Viewed 492 times

2

I have a dll which is responsible for carrying out the consultations in the bank. Therein dll, in the connection class, I have a method that opens the connection to the bank and returns the connection to me, as shown 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;
}

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

That one dll is consumed by a web application using MVC 4 with C# and the .Net Framework 4.0.

When I use that dll on a project Windows Forms I can connect to the database without problems, but when I use in a system MVC or WebForms an error occurs in connection with the database.

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

Erro de conexão

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 can connect normally, but in the local, to use debug mode, I cannot connect to the database.

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

  • In the Oracle database server have the logs, check if this connection is coming, or check if it is going through the firewall !!! You also have View Details in Exception check the most detailed error data !!!

  • Are you using full OSI or Express? Your error may be being caused by having an Oracle 32bit client and running a 64bit application, or vice versa. Try switching between 32 and 64bit in your application (directly in the pool if it’s IIS or Visual Studio).

  • @Cezar will check the logos of the bank and the issue of firewall. The details of the exception have nothing, I have looked several times.

  • @Ciganomorrisonmendez am not using any Nuget package, only the own dll that is used in the company’s projects.

  • So that’s it. I’ll answer.

  • @Marcusvinicius I’m using IIS Express, which comes with VS 2013 Express For Web. I’m going to check out this question you mentioned

  • 1

    The option to use the 64bit version of IIS Express is on TOOLS > Options > Projects And Solutions > Web Projects > [x] Use the 64 bit version of IIS Express for web sites and projects

  • @Marcusvinicius your solution worked. If you want to post an answer I accept it.

  • @Richarddias published the answer with an explanation of how to configure 32/64bit in Web apps . Net (http://answall.com/a/92072/23593)

Show 5 more comments

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 the 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, Inside IIS Managed, expand "Application Pools", locate the Pool your application is using, right-click > Advanced Settings:

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

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

  • If you are using IIS Express, inside 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":

inserir a descrição da imagem aqui

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 one in the problem. The file . csproj was set 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 file . csproj of my console application, it was as below:

<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 . csproj from 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 saving the dlls to be used, saving one part in bin/Release folder and another in bin/Debug folder.

1

The @Marcusvinicius response solved my problem for web projects, but I continued with a problem for desktop applications such as windows forms and console aplication.

Watching the @Hendrigwernner response I realized the tag <Prefer32Bit>false</Prefer32Bit>. I looked at the project properties and cleared this option in the project properties, in the tab build.

inserir a descrição da imagem aqui

Making this modification the project worked correctly and the connection error did not appear anymore.

1

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

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

PM> Install-Package Oracle.ManagedDataAccess
  • In the dll that makes the access to the Bank the version of . Net is the 3.5. This package does not give for this version. I know that referencing the DLL directly is not the best option, but it is the custom used so far in the company. Soon we’ll change that, but until then we have to use it like this.

  • Then it gets complicated. The way is to force 64 bits, as @Marcusvinicius put it. There’s no way to use one framework most recent?

  • Not yet, because there are several systems that are old and run on 3.5. I was able to create a new one using 4.0 to show some advantages, but still it is not possible to change all the applications. That’s why the dll that is shared should keep this version.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.