【发布时间】:2019-01-04 13:40:13
【问题描述】:
对于这个问题,已经有很多关于 SO 的问题。但是,我找到的所有答案都没有任何帮助。
我们有一个针对 net461 的 ASP.NET Core MVC 项目,以便我们可以将 Entity Framework 6 用于 Oracle 数据库。
相关问题
我自己和所有其他开发人员都让它在我们的 PC 上运行良好。但是,在部署到 IIS 服务器时,我得到以下信息:
Error ::Schema specified is not valid. Errors:
Oracle.ManagedDataAccess.EntityFramework.Resources.EFOracleStoreSchemaDefinition.ssdl(2,64) : error 0175: The ADO.NET provider with invariant name 'Oracle.DataAccess.Client' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.
Oracle.ManagedDataAccess.EntityFramework.Resources.EFOracleStoreSchemaDefinitionVersion3.ssdl(3,4) : error 0019: The EntityContainer name must be unique. An EntityContainer with the name 'Schema' is already defined.
Oracle.ManagedDataAccess.EntityFramework.Resources.EFOracleStoreSchemaDefinitionVersion3.ssdl(867,4) : error 0019: Each type name in a schema must be unique. Type name 'Oracle.Table' was already defined.
Oracle.ManagedDataAccess.EntityFramework.Resources.EFOracleStoreSchemaDefinitionVersion3.ssdl(877,4) : error 0019: Each type name in a schema must be unique. Type name 'Oracle.TableColumn' was already defined.
... and so on.
虽然我已经看到了 Oracle.ManagedDataAccess.dll 是连接到 Oracle 所需的全部内容,但我已经在服务器上安装了 11g 和 12c 64 位 Oracle 客户端。 如果我打开 64 位 ODBC 管理工具,我可以从我们的服务器连接到数据库,这意味着没有连接问题。
错误消息提到Oracle.DataAccess.Client,但我们使用的是Oracle.ManagedDataAccess.Client。在我们的代码、.csproj 或 packages.config 中,我们没有引用非托管 dll。
我在<DbProviderFactories> 中尝试了各种<clear /> 和<remove> 标签。我已将 Oracle 客户端安装位置的 Oracle.DataAccess.dll 直接复制到项目文件夹中。我已经卸载,重新安装,重新部署。我已将两个 DLL 添加到 GAC。似乎没有什么能摆脱这个错误。
以下是配置文件的相关部分:
<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.122.18.3, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</configSections>
<entityFramework>
<providers>
<provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.122.18.3, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<clear />
<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.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
<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.122.18.3" />
</dependentAssembly>
...
<connectionStrings>
<add name="<DB_MODEL_NAME>" connectionString="metadata=res://*/;provider=Oracle.ManagedDataAccess.Client;provider connection string='<CONNECTION_STRING>'" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
注意连接字符串中的metadata=res://*/ 位。在我们的 PC 上,这读作 res://*/<DB_MODEL_NAME>.csdl|res://*/<DB_MODEL_NAME>.ssdl|res://*/<DB_MODEL_NAME>.msl。我根据其他一些帖子将其更新为metadata=res://*/。没有这个,抛出的错误是:
Error ::Unable to load the specified metadata resource.
我已经尝试了来自 this article 的建议,但似乎没有一个有效。如果我给它一个包含 .edmx 的程序集名称,它会抱怨它找不到那个 DLL,即使它就在部署的文件夹中。
【问题讨论】:
标签: oracle iis entity-framework-6 asp.net-core-mvc