C# 找不到类型或命名空间名称“OracleConnection”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12220095/
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
The type or namespace name 'OracleConnection' could not be found
提问by jaredk
I am getting this error every time I try to debug my program:
每次尝试调试我的程序时,我都会收到此错误:
CS0246: The type or namespace name 'OracleConnection' could not be found (are you missing a using directive or an assembly reference?)
CS0246:找不到类型或命名空间名称“OracleConnection”(您是否缺少 using 指令或程序集引用?)
This occurs on the declaration private readonly OracleConnection oracleConnection;(and in a few other places as well)
这发生在声明上private readonly OracleConnection oracleConnection;(以及其他一些地方)
I have been trying a number of suggested solutions but so far none have worked:
我一直在尝试一些建议的解决方案,但到目前为止都没有奏效:
- I have added a reference to the
System.Data.OracleClient.dll - My target framework is set to
.NET Framework 4 - I have tried both including
using System.Data.OracleClientand manually writing outSystem.Data.OracleClient.OracleConnection
- 我已经添加了对
System.Data.OracleClient.dll - 我的目标框架设置为
.NET Framework 4 - 我试过包括
using System.Data.OracleClient和手动写出System.Data.OracleClient.OracleConnection
EDIT:The code I am using is as follows:
编辑:我使用的代码如下:
using System;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Foo
{
public class DBHandler
{
private readonly OracleConnection oracleConnection;
private readonly OracleCommand oracleCommand;
private readonly OracleDataAdapter oracleAdapter;
Nothing has worked so far, so any suggestions would be appreciated.
到目前为止没有任何工作,所以任何建议将不胜感激。
采纳答案by jaredk
I managed to solve this one, though I don't know how what I changed affected anything. The DBHandler.cs file was located in a folder called "App_Code". Moving the file up one level (into the main project folder) seems to have solved the error.
我设法解决了这个问题,尽管我不知道我所做的更改如何影响任何事情。DBHandler.cs 文件位于名为“App_Code”的文件夹中。将文件上移一层(进入主项目文件夹)似乎解决了错误。
回答by Adil
First of all, for Oracle, System.Data.OracleClient has been deprecated and therefore it's not been recommended now. For details, please visit ADO.NET Team Blog Post
首先,对于 Oracle,System.Data.OracleClient 已被弃用,因此现在不推荐使用。有关详细信息,请访问ADO.NET 团队博客文章
What is recommended is Oracle client published by Oracle corporation. Download the Oracle Data Access component from Oracle .NET Developer Center
推荐使用Oracle公司发布的Oracle客户端。从Oracle .NET Developer Center下载 Oracle Data Access 组件
Then in the same way, you can use OracleConnection, OracleCommand etc. by adding reference to Oracle.Client dll.
然后以同样的方式,您可以通过添加对 Oracle.Client dll 的引用来使用 OracleConnection、OracleCommand 等。
Further please note this library wont be available for .NET 4 Client Profile.
此外请注意,此库不适用于 .NET 4 Client Profile。
回答by Zeph
I think the using directive got removed.
我认为 using 指令被删除了。
using System;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data.OracleClient; //Add This
using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Foo {
public class DBHandler
{
private readonly OracleConnection oracleConnection;
private readonly OracleCommand oracleCommand;
private readonly OracleDataAdapter oracleAdapter;
Did you maybe try each of those steps individually and then set them back when they didn't work?
您是否可能会单独尝试这些步骤中的每一个,然后在它们不起作用时将它们放回原处?
回答by SAGAR KALBURGI
Project->Add reference->Oracle.DataAccess
Here there are two versions- 2.something and 4.something.
When I selected the version 4 it did't resolve the namespace, but when I selected the version 2 it resolved!!
Project->Add reference->Oracle.DataAccess
这里有两个版本——2.something 和4.something。当我选择版本 4 时它没有解析命名空间,但是当我选择版本 2 时它解析了!!

