C# 命名空间“System.Data”中不存在类型或命名空间名称“OracleClient”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12218027/
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 'OracleClient' does not exist in the namespace 'System.Data'
提问by jaredk
When trying to run my code, I receive the following error:
尝试运行我的代码时,我收到以下错误:
CS0234: The type or namespace name 'OracleClient' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
CS0234:命名空间“System.Data”中不存在类型或命名空间名称“OracleClient”(您是否缺少程序集引用?)
I have included references to System.Data.dlland System.Data.OracleClient.dll, but I am still getting this error.
我已经包含了对System.Data.dll和 的引用System.Data.OracleClient.dll,但我仍然收到此错误。
The error is being caused by the line using System.Data.OracleClientin my namespace declaration.
该错误是由using System.Data.OracleClient我的命名空间声明中的行引起的。
采纳答案by Jon Hanna
The using System.Data.OracleClientdirective means that that namespace should be considered when trying to determine what non-full names mean.
该using System.Data.OracleClient指令意味着在尝试确定非全名的含义时应考虑该命名空间。
Adding a reference, means you add a reference to a given assembly, in this case System.Data.OracleClient.dll. From VisualStudio, SharpDevelop or MonoDevelop you will see a references folder in the project explorer view. Right click and "Add Reference" (VisualStudio and SharpDevelop) or "Edit References" (MonoDevelop), and add in System.Data.OracleClient.dll
添加引用意味着添加对给定程序集的引用,在本例中为 System.Data.OracleClient.dll。在 VisualStudio、SharpDevelop 或 MonoDevelop 中,您将在项目资源管理器视图中看到一个引用文件夹。右键单击并“添加引用”(VisualStudio 和 SharpDevelop)或“编辑引用”(MonoDevelop),然后添加 System.Data.OracleClient.dll
If using nant you'll need to edit your nant script.
如果使用 nant,则需要编辑 nant 脚本。
Assemblies and namespaces overlap, but aren't quite the same. The reference means you can use e.g. System.Data.OracleClient.OracleDataReaderbecause the project now knows what assembly the code for that lives in. The usingdirective means you need only type OracleDataReader. There tends to be a heavy match between assemblies and namespaces because that makes life easier for everyone, but there are both times when an assembly has classes from more than one namespace, and when a namespace is split over more than one assembly. A classic example is that mscorlib has a lot of classes from System, System.Collections, System.IOetc. that you couldn't really hope to build a .NET project without (including some that .NET uses itself), while System.dll has a bunch more from exactly the same namespaces that you could feasibly get by without using (but you still will 99% of the time).
程序集和命名空间重叠,但并不完全相同。引用意味着您可以使用例如,System.Data.OracleClient.OracleDataReader因为项目现在知道该代码所在的程序集。using指令意味着您只需要键入OracleDataReader。程序集和命名空间之间往往存在大量匹配,因为这使每个人的生活都更轻松,但有时程序集具有来自多个命名空间的类,以及命名空间被拆分到多个程序集时。一个经典的例子是 mscorlib 有很多类来自System, System.Collections,System.IO等等,你真的不希望在没有(包括一些 .NET 自己使用的项目)的情况下构建一个 .NET 项目,而 System.dll 有更多来自完全相同的命名空间,你可以在不使用的情况下可行地获得(但你在 99% 的情况下仍然会)。
Unless you're writing an absolutely massive library though, with thousands of classes covering overlapping use-cases, your own assemblies should work with a single namespace - or at most a single one with some other namespaces within that one, like JaredksGreatCodehaving JaredksGreatCode.UserInterfacewithin it - per single DLL.
除非你写一个绝对庞大的图书馆,虽然,与成千上万的覆盖重叠的用例类,你自己的组件时,应当有一个命名空间的工作-或者至多一个一个与一个内一些其他的命名空间,就像JaredksGreatCode有JaredksGreatCode.UserInterface内它-每个 DLL。
回答by Aghilas Yakoub
You add reference on System.Data.OracleClient.dll.
您在 上添加引用System.Data.OracleClient.dll。
回答by Jamie
I had to add a reference to the Oracle.DataAccess.dll, and then I had to manually associate all the references to OracleClient.blahblahwith
Oracle.DataAccess.Client.blahblah.
我必须添加对 的引用Oracle.DataAccess.dll,然后我必须手动将所有引用OracleClient.blahblah与
关联Oracle.DataAccess.Client.blahblah。
Hopefully this helps someone else.
希望这对其他人有帮助。
回答by Swapneel Macwan
Add a reference into your web config file as shown below. This works for me.
将引用添加到您的 Web 配置文件中,如下所示。这对我有用。
<!--REFERENCES-->
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
回答by caot
The following worked for me:
以下对我有用:
Visual Studio --> WEBSITE --> Add Reference... --> Framework --> System.Data.OracleClient[check this option]
Visual Studio --> 网站 --> 添加引用... --> 框架 --> System.Data.OracleClient[勾选这个选项]

