1
My wpf program worked very well. They moved it to make some changes. Well, they asked me to change some folders in the application. Before I make any changes I went to run the application and is giving me this error:
The 'Oracle.DataAccess.Client.Oracleconnection' type initializer triggered an exception
The fact occurs in this line:
var diferenca = _listaCommiter().Except(_listaFarm());
This is the complete code of the method:
private List<string> RetornaDiferenca()
{
List<string> listaDiferenca = new List<string>();
try
{
var diferenca = _listaCommiter().Except(_listaFarm());
foreach (var _diferenca in diferenca)
{
listaDiferenca.Add(_diferenca);
}
diferenca = null;
return listaDiferenca;
}
catch (Exception ex)
{
string r = ex.Message;
return null;
}
}
That is the method _listaFarm()
private List<string> _listaFarm()
{
List<string> lista = new List<string>();
ConexaoBanco cb = new ConexaoBanco();
lista = cb.CriaConexao();
return lista;
}
It is a select on a BD Tablea.
I realized that in the method where I take the connection, is giving the problem. This is the method:
public List<string> CriaConexao()
{
string conexao = ConfigurationManager.ConnectionStrings["FarmExternaConnect"]
.ConnectionString;
List<string> listaArquivoFarmExterna = new List<string>();
OracleConnection conn = new OracleConnection(conexao);
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "select path, arquivo from gh_arquivos_farm_externa";
cmd.CommandType = CommandType.Text;
try
{
OracleDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
listaArquivoFarmExterna.Add(dr.GetString(0) + dr.GetString(1));
}
return listaArquivoFarmExterna;
}
catch(Exception ex)
{
return null;
}
finally
{
conn.Close();
cmd.Dispose();
}
The mistake comes in this line:
OracleConnection conn = new OracleConnection(conexao);
This is the Inner Exception:
The Provider is not compatible with the version of Oracle client
My connection string:
<add name="FarmExternaConnect" connectionString="Data Source=DESENV; Persist Security Info=True; User ID=Eu; Password=teste"/>
More lines in my app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxx"
requirePermission="false"/>
<section name="oracle.manageddataaccess.client"
type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxx"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<appSettings>
<!-- Pastas de Projetos .NET que estão na Farm Externa, separados por vírgula -->
<add key="ProjetosDotNet" value="teste"/>
</appSettings>
<connectionStrings>
<add name="FarmExternaConnect" connectionString="Data Source=DESENV; Persist Security Info=True; User ID=user; Password=teste"/>
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client"/>
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver"
type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxx"/>
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<publisherPolicy apply="no"/>
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="xxxxxxxxxxxxxxx" culture="neutral"/>
<bindingRedirect oldVersion="4.121.0.0 - 4.65535.65535.65535" newVersion="4.121.2.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<oracle.manageddataaccess.client>
<version number="*">
<dataSources>
<dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) "/>
</dataSources>
</version>
</oracle.manageddataaccess.client>
</configuration>
Have you managed to solve it this way? If yes, mark it as an answer so that others can take advantage of the solution :)
– Uilque Messias
I can only do it after two days. Rules of the site.
– pnet