0

我将 Code First EF 与 Oracle ODP.Net 一起使用,并尝试通过 VS2012 中的“EF Powertools Beta 3”重新生成视图。

我最近开始在视图生成上遇到以前没有的错误,所以我猜我有一些配置错误,因为错误与 SQL Server 而不是 Oracle 有关。

完整的错误如下:

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)

我当前的 app.config 是:

<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>

有谁知道我错了什么配置?

4

1 回答 1

0

看起来这是配置的问题。

当我将连接字符串上的名称更改为 Context 类名称并提供连接字符串提供程序名称后,EF 电动工具成功生成了我的视图。

我还从 DataAccess 项目(包含 EF 代码)中删除了所有配置,而是将配置添加到调用 DataAccess 层的主 WebService 项目中。

我使用的最终配置是:

<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>

我不能保证这对所有人都有效,但它可能对其他人有所帮助!

于 2013-06-10T11:47:00.967 回答