C# ODP.NET 错误无法找到请求的 .Net Framework 数据提供程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17528252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ODP.NET error Unable to find the Requested .Net Framework Data Provider
提问by Captain Kenpachi
I am trying to develop an ASP.NET MVC 4.0 application using Oracle 11g Express and the .NET 4.0 framework. I can connect to the DB using the ODP.NET provider and can also generate my EDMX against the database. What I can't do is query the underlying DB using entity framework. When instantiating my DbContext using the connectionString Visual Studio generated, I get the following error:
我正在尝试使用 Oracle 11g Express 和 .NET 4.0 框架开发 ASP.NET MVC 4.0 应用程序。我可以使用 ODP.NET 提供程序连接到数据库,还可以针对数据库生成我的 EDMX。我不能做的是使用实体框架查询底层数据库。使用 Visual Studio 生成的 connectionString 实例化我的 DbContext 时,出现以下错误:
Unable to find the requested .Net Framework Data Provider. It may not be installed
无法找到请求的 .Net Framework 数据提供程序。它可能没有安装
However, it is installed because
但是,安装它是因为
- I can see the dll in the GAC.
- It is mentioned in machine.config.
- It is referenced by my project.
- I actually use it to generate my EDMX from the database.
- I have verified that I am referencing the correct version (4.112.3.0) everywhere
- 我可以在 GAC 中看到 dll。
- machine.config 中提到了它。
- 它被我的项目引用。
- 我实际上使用它从数据库生成我的 EDMX。
- 我已经确认我在任何地方都引用了正确的版本 (4.112.3.0)
I am running the code locally on Cassini and my hardware is 32-Bit architecture, so I would assume I would only be able to use 32-Bit DLL's, so it's not an architecture problem.
我在 Cassini 本地运行代码,我的硬件是 32 位架构,所以我假设我只能使用 32 位 DLL,所以这不是架构问题。
The specific bit of code is as such:
代码的具体位是这样的:
public class MyContext : ObjectContext, IUnitOfWork
{
public MyContext()
: base(ConfigurationManager
.ConnectionStrings["OracleEntities"]
.ConnectionString)//Connectionstring is verified
{}
}
please help me before I leave everything, grow a beard and go live in the mountains somewhere.
在我离开一切之前,请帮助我,留胡子,然后去山上的某个地方生活。
SOLUTION: Since I haven't seen any mention of the solution, I'll mention it here for future generations. Andrei below asked about my connection string format and although I was scheptical, I went and had a look. This is what I saw:
解决方案:由于我还没有看到任何提及该解决方案的内容,因此我将在此提及以供后代使用。下面的 Andrei 询问了我的连接字符串格式,虽然我持怀疑态度,但我还是去看了看。这是我看到的:
metadata=res://*/OracleModel.csdl|res://*/
OracleModel.ssdl|res://*/
OracleModel.msl;
provider=provider=Oracle.DataAccess.Client;
provider connection string="DATA SOURCE=localhost:1521;
PASSWORD=xxx;PERSIST SECURITY INFO=True;USER ID=xxx
Now, pay special attention to the line
现在,要特别注意这条线
provider=provider=Oracle.DataAccess.Client;
it should, in fact, read
事实上,它应该读
provider=Oracle.DataAccess.Client;
otherwise you're telling EF to use [provider.dll], which isn't a real thing. Also note that it seems that the providerName property of the connectionString element seems to have been overridden or ignored.
否则你告诉 EF 使用 [provider.dll],这不是真的。另请注意, connectionString 元素的 providerName 属性似乎已被覆盖或忽略。
UPDATE 2: If this STILL does not help, have a look at machine.config. You should see the following section:
更新 2:如果这仍然没有帮助,请查看 machine.config。您应该看到以下部分:
<add name="Oracle Data Provider for .NET" invariant="Oracle.DataAccess.Client" description="Oracle Data Provider for .NET" type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
<remove invariant="Oracle.DataAccess.Client" />
</DbProviderFactories>
If <remove invariant="Oracle.DataAccess.Client" />is present, comment it out and try again, otherwise, if it's not there, put it in and try again.
如果<remove invariant="Oracle.DataAccess.Client" />存在,将其注释掉并重试,否则,如果不存在,则将其放入并重试。
采纳答案by Andrei
Try this connection string format:
试试这个连接字符串格式:
Provider=msdaora;Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;
Check out connection string examples for Oracle db http://www.connectionstrings.com/oracle
查看 Oracle db http://www.connectionstrings.com/oracle 的连接字符串示例
回答by Jose G
Another possible solution for someone out there.
另一个可能的解决方案。
My webapp was working well on my test server but when I started to develop for my live server I got the same error: Unable to find the requested .Net Framework Data Provider. It may not be installed
我的 webapp 在我的测试服务器上运行良好,但是当我开始为我的实时服务器开发时,我遇到了同样的错误:无法找到请求的 .Net Framework 数据提供程序。它可能没有安装
If you compare the two connection strings below you will notice that the one causing my issue had the "Managed" word in the provider name. I'm actually using the unmanaged version of the Oracle provider. Hence I was getting the error on my live server and not on my test server.
如果您比较下面的两个连接字符串,您会注意到导致我的问题的连接字符串在提供程序名称中带有“托管”字样。我实际上使用的是 Oracle 提供程序的非托管版本。因此,我在我的实时服务器上而不是在我的测试服务器上收到错误。
**ORIGINAL:**
connectionString="DATA SOURCE=192.168.10.101:1521/dataconn;PASSWORD=password;PERSIST SECURITY INFO=True;USER ID=DataConn" providerName="Oracle.ManagedDataAccess.Client"
**NEW:**
connectionString="DATA SOURCE=192.168.10.101:1521/dataconn;PASSWORD=password;PERSIST SECURITY INFO=True;USER ID=DataConn" providerName="Oracle.DataAccess.Client"
回答by Joseph Wykel
This error is a little misleading because it can also be caused by running under the wrong CPU contexts. Make sure you are allowing for 32-bit if using a 32-bit Oracle driver. This can be done as a setting under IIS or you can setup your application to run as an IIS Express application.
这个错误有点误导,因为它也可能是在错误的 CPU 上下文下运行引起的。如果使用 32 位 Oracle 驱动程序,请确保您允许 32 位。这可以作为 IIS 下的设置完成,也可以将应用程序设置为作为 IIS Express 应用程序运行。
回答by Greg Z.
For us it was 32 vs. 64 bit process.
对我们来说,这是 32 位和 64 位进程。
The server is 64 bit. The ODP.NET (Oracle Client) installed is also 64 bit. Our application compiled with the Target platform "Any CPU" and "Prefer 32-bit" flag SET:
服务器是64位的。安装的 ODP.NET(Oracle 客户端)也是 64 位的。我们的应用程序使用目标平台“任何 CPU”和“首选 32 位”标志 SET 编译:
was running as 32 bit process. Once recompiled with the flag un-checked everything started to work.
作为 32 位进程运行。使用未选中的标志重新编译后,一切都开始工作。
回答by lakant
I got the same error when opening the page via IIS, 64bit Win7.
我在通过 IIS、64 位 Win7 打开页面时遇到了同样的错误。
My solution is:
我的解决办法是:
Go to IIS manager --> Application Pool --> Advanced Settings --> Enable 32-Bit Applications.
转到 IIS 管理器 --> 应用程序池 --> 高级设置 --> 启用 32 位应用程序。


回答by James Lawruk
Here is what worked for me. My server already had an Oracle client installed. (version 11.2.0)
这对我有用。我的服务器已经安装了 Oracle 客户端。(版本 11.2.0)
Download from the ODAC for Windows Downloadspage the ODP.NET Managed Driver
(I chose the Oct. 2015 release, 2.43 MB download)Extract the zip file, grab the \lib\net40\Oracle.ManagedDataAccess.dll, and place it in the bin folder.
In the web.config, add a reference to the ODP.NET Managed Driver under system.data\DbProviderFactories explained in this answer.
从ODAC for Windows 下载页面下载ODP.NET 托管驱动程序
(我选择了 2015 年 10 月版本,2.43 MB 下载)解压 zip 文件,获取 \lib\net40\Oracle.ManagedDataAccess.dll,并将其放入 bin 文件夹中。
在 web.config 中,在 system.data\DbProviderFactories 下添加对 ODP.NET Managed Driver 的引用,在此答案中解释。
That's it.
就是这样。
To confirm, run this answer's codeto see if the ODP.NET provider is installed. You should see ODP.NET, Managed Driver in the list.
要确认,请运行此答案的代码以查看是否安装了 ODP.NET 提供程序。您应该会在列表中看到 ODP.NET,托管驱动程序。
回答by roadrunner71
I had a similar problem. It was resolved by adding a NuGet package. I already had Oracle.ManagedDataAccess.EntityFramework available in my references from the install of ODT but it was giving an Entity Framework 5 conflict with 6 in the detailed log. Once I added the NuGet package, everything started working.
我有一个类似的问题。通过添加 NuGet 包解决了这个问题。我已经在 ODT 安装的参考中提供了 Oracle.ManagedDataAccess.EntityFramework,但它在详细日志中给出了 Entity Framework 5 与 6 的冲突。添加 NuGet 包后,一切都开始工作了。
- To install, right click References --> Manage NuGet Packages… --> Search for Oracle in the Browse tab --> Choose Oracle.ManagedDataAccess.EntityFramework and install the latest version.
- 要安装,请右键单击 References --> Manage NuGet Packages... --> 在 Browse 选项卡中搜索 Oracle --> 选择 Oracle.ManagedDataAccess.EntityFramework 并安装最新版本。
回答by Johnny Wu
I actually downloaded the ODAC and install it. Then I Add a Reference and found the package roadrunner71 mentioned.
我实际上下载了 ODAC 并安装了它。然后我添加了一个引用,找到了提到的包roadrunner71。

