Search code examples
entity-frameworkodp.net

Generating Code First Views with Oracle


I am using Code First EF with Oracle ODP.Net, and am trying to re-generate the Views via "EF Powertools Beta 3" within VS2012.

I have recently started getting errors on the view generation which I didn't before, so I'm guessing that I have some config wrong, as the error relates to SQL Server rather than Oracle.

The error in full is given as:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. --->
System.Data.ProviderIncompatibleException: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct. --->
System.Data.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. --->
System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

My current app.config is:

<configuration>
   <configSections>
      <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
   </configSections>

  <dataConfiguration defaultDatabase="STD" />
  <connectionStrings>
      <add name="STD" connectionString="Data Source=localhost:1521/ora10g01;Persist Security Info=false;User ID=user;Password=pass;Connection Timeout=30;Decr Pool Size=1;Incr Pool Size=5;Min Pool Size=1;Max Pool Size=20;Pooling=true;" />
   </connectionStrings>
   <entityFramework>
       <defaultConnectionFactory type="STDConnectionFactory, STD.DataAccess">
           <parameters>
               <parameter value="v11.0" />
           </parameters>
       </defaultConnectionFactory>
   </entityFramework>
</configuration>

Does anyone have any idea about what bit of config I have wrong?


Solution

  • It looks like this was an issue with config.

    When I changed the name on the connection string to be the Context class name, and after I provided the connection string provider name, the EF power tool successfully generated my views.

    I also stripped out all config from the DataAccess project (which holds the EF code), and instead added the config to the main WebService project, which invokes the DataAccess layer.

    The final config I used was:

    <configuration>
        <configSections>
            <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </configSections>
    
        <dataConfiguration defaultDatabase="STD" />
        <connectionStrings>
           <add name="STDContext" providerName="Oracle.DataAccess.Client" connectionString="Data Source=localhost:1521/ora10g01;Persist Security Info=false;User ID=user;Password=pass;Connection Timeout=30;Decr Pool Size=1;Incr Pool Size=5;Min Pool Size=1;Max Pool Size=20;Pooling=true;" />
        </connectionStrings>
        <entityFramework>
           <defaultConnectionFactory type="STDConnectionFactory, STD.DataAccess">
              <parameters>
                  <parameter value="NICK />
              </parameters>
           </defaultConnectionFactory>
        </entityFramework>
    </configuration>
    

    I can't guarantee this will work for everyone, but it may help someone else!