2017-09-26 108 views
0

我正在创建一个项目,这是我第一次连接到MVC项目中的Oracle数据库。我发现源herehere,我遵循这封信的指示,但我仍然无法让它工作。将实体框架连接到Oracle 11g不起作用

我都遵循的步骤是:
1)安装了Oracle开发人员参考Oracle库的Visual Studio
2)安装实体框架版本6
3)工具
4)增加了Oracle提供给Web我的项目的配置和应用配置 5)尝试从数据库模式添加新的实体数据模型,但Oracle数据提供程序在设置数据连接时从不显示。

这里是我的webconfig:

<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.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/> 
</configSections> 
<connectionStrings> 
    <add name="MinimumInventory" connectionString="Server=SQLServerName\ServerInstance;Initial Catalog=DatabaseName;Integrated Security=True" 
     providerName="System.Data.SqlClient"/> 
    <add name="ThirdWaveData" connectionString="Server=OracleServerName;Initial Catalog=databaseName; User Id=myID; Password=myPassword; Integrated Security=True" 
     providerName="Oracle.ManagedDataAccess.Client"/> 
</connectionStrings> 
<providers> 
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" /> 
</providers> 

,你可以看到,我也连接到SQL服务器,如果在所有效果的解决方案。

回答

0

下载oracle 12驱动程序/客户端很重要。否则,您需要在生产服务器上安装Oracle。

您在数据库项目中引用了Oracle.DataAccess。 enter image description here

代替ConfigurationManager中,你可以使用以下方法:https://github.com/codingfreak/cfUtils/blob/d0769751ac64e8a67aea028821bef2a270dc525c/Logic/Logic.Utils/Utilities/ConfigurationUtil.cs

在web.config中我的连接字符串如下所示:

<connectionStrings> 
    <add name="oracle" connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.123)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=PD)));User ID=MyUSER;Password=MyPassword;" /> 
    </connectionStrings>