1

I have created to apps, first with ODP.Net and without Entity - works great.

        static void Main(string[] args)
    {
        OracleConnection con = new OracleConnection();

        //using connection string attributes to connect to Oracle Database
        con.ConnectionString = "user id=****;password=****;data source=" +
            "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server.org.net)(PORT=1521))(CONNECT_DATA=(SERVER=dedicated)(SERVICE_NAME=ora1)))";
        con.Open();
        Console.WriteLine("Connected to Oracle" + con.ServerVersion);

        OracleCommand command = con.CreateCommand();
        command.CommandText = "SELECT ITEM FROM TEST.ORDERS";

        OracleDataReader reader = command.ExecuteReader();

        while (reader.Read())
        {
            Console.WriteLine("\t{0}",
                reader[0]);
        }
        reader.Close();

        // Close and Dispose OracleConnection object
        con.Close();
        con.Dispose();
        Console.WriteLine("Disconnected");
        Console.ReadKey();
    }

Second program is using ODP.Net and EntityFramework and manaly created Entity Data Model class (which was tested on Npgsql.EntityFramework and works great, perfect copy of the database from Oracle). The application returns the error:

Exception Info: System.TypeInitializationException
Stack:
   at Oracle.ManagedDataAccess.Client.OracleClientFactory.CreateConnection()
   at System.Data.Entity.Internal.LazyInternalConnection.CreateConnectionFromProviderName(System.String)
   at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(System.Configuration.ConnectionStringSettings)
   at System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(System.String, System.Data.Entity.Internal.AppConfig)
   at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
   at System.Data.Entity.Internal.LazyInternalConnection.get_ProviderName()
   at System.Data.Entity.Internal.LazyInternalContext.get_ProviderName()
   at System.Data.Entity.Internal.DefaultModelCacheKeyFactory.Create(System.Data.Entity.DbContext)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()

I don't know what is wrong. This is my app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    <section name="Oracle.ManagedDataAccess.Client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
  </startup>
  <system.data>
    <DbProviderFactories>
      <add name="Npgsql Data Provider" invariant="Npgsql" description="Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql"/>
      <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=89b483f429c47342"/>
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="TestContext" connectionString="Server=localhost;Database=testDb;User Id=***;Password=***;" providerName="Npgsql"/>
    <add name="OracleDbContext" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=***;Password=***;Data Source=SampleDataSource2"/>
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb"/>
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework"/>
      <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
    </providers>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <publisherPolicy apply="no"/>
        <assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" 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))) "/>
        <dataSource alias="SampleDataSource2" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server.org.net)(PORT=1521))(CONNECT_DATA=(SERVER=dedicated)(SERVICE_NAME=ora1)))"/>
      </dataSources>
    </version>
    <settings>
      <setting name="TraceLevel" value="7" />
      <setting name="TraceFileLocation" value="C:\"/>
    </settings>
  </oracle.manageddataaccess.client>
</configuration>
6
  • How did you install ODP.NET? If you got it from NuGet make sure to get the one with "Official" in the title. A proper installation of ODP.NET will add entries to machine.config (or your app.config) to make it able to be used as a ClassFactory. Commented Feb 27, 2015 at 20:56
  • Yes, I used NuGet and "Official" version - similarly, as I did for PostgreSQL (which worked). In app.confg I added only SampleDataSource2, rest is autogenerated. Look at connectionString - 'Data Source=SampleDataSource2' is this OK? Commented Feb 27, 2015 at 21:26
  • Is there by any chance an internal or nested exception being thrown that contains an ORA- error? (For example ORA-12145) When the exception pops up look at the details and see if you can drill down and see an ORA error. That may be all this is. Commented Mar 1, 2015 at 0:23
  • I found one bug and now I have something like this: ORA-00955 when doing this: dbContext.Orders.Select(m => m.PlanNo).Distinct().OrderBy(m => m); Commented Mar 1, 2015 at 13:58
  • Sounds like you have moved way past the connection error and are onto something entirely different. Commented Mar 2, 2015 at 18:23

1 Answer 1

1

There was a bug in app.config section:

<oracle.manageddataaccess.client>

I had to remove:

<settings>

Nevertheless, the application still does not work, but for a different reason.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah! It was trying to write a trace to C:\ which is not allowed for non admin processes!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.