我試圖通過實體框架連接到Oracle數據庫。使用MVC 4將實體框架與Oracle 11g連接時面臨問題
我已經創建了兩個項目:
- 數據訪問項目
- MVC4 Web項目
這是工作的罰款,如果我嘗試使用一個控制檯應用程序,App.config中進行連接,但在嘗試使用Web應用程序和web.config進行連接時遇到問題。
我在數據訪問項目中添加了使用Nuget的軟件包。我引用了Web項目中的數據訪問DLL並嘗試調用Oracle連接。
Package.config
<packages>
<package id="EntityFramework" version="6.0.2" targetFramework="net45" />
<package id="odp.net.x64" version="112.3.20" targetFramework="net45" />
<package id="Oracle.ManagedDataAccess" version="12.1.021" targetFramework="net45" />
<package id="Oracle.ManagedDataAccess.EntityFramework" version="12.1.021" targetFramework="net45" />
</packages>
的Web.Config
<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>
<connectionStrings>
<clear/>
<add name="OracleDbContext" providerName="Oracle.ManagedDataAccess.Client"
connectionString=" Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host address)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=oracle))); User Id=userid;Password=pwd;"/>
</connectionStrings>
<entityFramework>
<!--<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>-->
<defaultConnectionFactory type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" >
</defaultConnectionFactory>
<providers>
<provider invariantName="Oracle.ManagedDataAccess.Client"
type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<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>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<publisherPolicy apply="no"/>
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<oracle.manageddataaccess.client>
<version number="*">
<dataSources>
<dataSource alias="OracleDbContext" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hostname)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=oracle))); User Id=userid;Password=pwd;"/>
</dataSources>
</version>
</oracle.manageddataaccess.client>
</configuration>
我面對以下問題:
實體框架提供程序類型「Oracle.ManagedDataAccess .EntityFramework.EFOracleProv在具有不變名稱「Oracle.ManagedDataAccess.Client」的ADO.NET提供程序的應用程序配置文件中註冊的iderServices,Oracle.ManagedDataAccess.EntityFramework,版本= 6.121.2.0,Culture = neutral,PublicKeyToken = 89b483f429c47342無法加載。確保使用了程序集限定名稱,並且該程序集可用於正在運行的應用程序。有關更多信息,請參閱http://go.microsoft.com/fwlink/?LinkId=260882。
請讓我知道我該如何解決這個問題。
Web項目找不到「Oracle.ManagedDataAccess」庫,可能需要將它們添加到Web項目中?您也可以嘗試將Nuget包添加到Web項目中。 – jjj