将 C# 连接到 Oracle

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1626636/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 19:17:50  来源:igfitidea点击:

Connecting C# to Oracle

c#oracle

提问by zendar

What is the best library/driver to connect C# (.NET) application to Oracle 10g and 11g.
Current options that I found are:

将 C# (.NET) 应用程序连接到 Oracle 10g 和 11g 的最佳库/驱动程序是什么。
我发现的当前选项是:

  1. Oracle client that comes with database installation
  2. Oracle Instant Client (which is a bit confusing since it has 6-8 versions for number of operating systems)
  3. Microsoft ODBC ? (Can this be used?)
  4. ODP.Net - is this separate product or is it included in 1. and 2. ?
  1. 安装数据库自带的Oracle客户端
  2. Oracle Instant Client(这有点令人困惑,因为它有 6-8 个版本的操作系统)
  3. 微软 ODBC ? (这个可以用吗?)
  4. ODP.Net - 这是单独的产品还是包含在 1. 和 2. 中?

Can somebody explain differences?

有人可以解释差异吗?

I am planning C# application that will do basic CRUD operations on Oracle database. Which library/driver is smallest and easiest to install?

我正在计划将在 Oracle 数据库上执行基本 CRUD 操作的 C# 应用程序。哪个库/驱动程序最小且最容易安装?

Edit:
General recommendation is to use ODP.Net. Now, can somebody please explain or point to answer about differences between client install packages. I found 3 different clients for Oracle 11g:

编辑:
一般建议使用 ODP.Net。现在,有人可以解释或指出有关客户端安装包之间差异的答案。我为 Oracle 11g 找到了 3 个不同的客户端:

So, which of those is enough for development? Oracle documentation is painfully detailed, but says nothing about differences between those client packages. I would go with smallest (Instant Client). Is it best choice?

那么,哪一个是足够发展的呢?Oracle 文档非常详细,但没有说明这些客户端包之间的差异。我会选择最小的(即时客户端)。是最好的选择吗?

Edit 2:
I am using .Net 3.5

编辑 2:
我正在使用 .Net 3.5

采纳答案by Christian13467

To connect C# to oracle you need a data provider for .net. This can be one of the following:

要将 C# 连接到 oracle,您需要一个用于 .net 的数据提供程序。这可以是以下之一:

  • ODP.Net (Oracle)
  • System.Data.OracleClient (Microsoft)
  • ODBC (Oracle)
  • OLEDB (Oracle)
  • DataDirect ADO.NET Data Provider for Oracle (DataDirect)
  • may be some other provider
  • ODP.Net (甲骨文)
  • System.Data.OracleClient (Microsoft)
  • ODBC (甲骨文)
  • OLEDB (甲骨文)
  • 适用于 Oracle 的 DataDirect ADO.NET 数据提供程序 (DataDirect)
  • 可能是其他一些提供者

Allof this data provider need an oracle client installed. There is no standalone library as jdbc14.jar as in java. You have 2 choices deploying an oracle client:

所有这些数据提供者都需要安装一个 oracle 客户端。没有像 java 中的 jdbc14.jar 这样的独立库。部署 oracle 客户端有两种选择:

  • full client (may be from database installation)
  • instant client
  • 完整客户端(可能来自数据库安装)
  • 即时客户端

ODP.Net, ODBC, OLEDB are part of full client. This is the "hard" way because an installation process must be run on every client runing your software. This is where the most megabytes are put on the client.
The instant clientis provided in different packages. This is the smallest way for deployment of an oracle client.

ODP.Net、ODBC、OLEDB 是完整客户端的一部分。这是一种“困难”的方式,因为必须在每个运行您的软件的客户端上运行安装过程。这是在客户端上放置最多兆字节的地方。
即时客户端在不同的软件包提供。这是部署 oracle 客户端的最小方式。

I would suggest using ODP.Net with Oracle Instant Client, because this easy to deploy and very very light weight.

我建议将 ODP.Net 与 Oracle Instant Client 一起使用,因为这易于部署且重量非常轻。

Which instant client packages do you need:

您需要哪些即时客户端软件包:

  • Pick version 11.1.0.6.0 (or newer where ODAC is provided)
  • Instant Client Package - Basic (if you need full language support)
  • Instant Client Package - ODAC
  • 选择版本 11.1.0.6.0(或提供 ODAC 的更新版本)
  • Instant Client Package - Basic(如果您需要完整的语言支持)
  • 即时客户端包 - ODAC

There are a lot of articles on stackoverflow about deployment of oracle instant client with c# applications.

stackoverflow 上有很多关于使用 c# 应用程序部署 oracle 即时客户端的文章。

EDIT:updated links and versions

编辑:更新的链接和版本

回答by Darin Dimitrov

Microsoft will deprecatethe System.Client.OracleClientnamespace so I think it will be best to use ODP.NET. Make sure you download the latest one (ODP.NET 11g) as previous versions had some issues.

微软将弃用System.Client.OracleClient,所以我认为这将是最好用的命名空间ODP.NET。请确保下载最新版本 (ODP.NET 11g),因为以前的版本存在一些问题。

回答by Alexander

ODP.NET is the best provider for accessing Oracle db, mostly - because it's the most native one, which differentiates it from ODBC by the following:

ODP.NET 是访问 Oracle db 的最佳提供者,主要是 - 因为它是最原生的,它与 ODBC 的区别如下:

  • better performance
  • ODP.NET provides access to advanced Oracle functionality, not available via ODBC .NET
  • ODP.NET does not use an extra data access bridge.
  • 更好的性能
  • ODP.NET 提供对高级 Oracle 功能的访问,而无法通过 ODBC .NET 获得
  • ODP.NET 不使用额外的数据访问桥。

ODBC can also be used but as mentioned above it's going to be slower and have limited functionality.

也可以使用 ODBC,但如上所述,它会更慢并且功能有限。

For making ODP.NET work you need the software listed here (and including oracle client): http://www.oracle.com/technology/tech/windows/odpnet/faq.html#install

为了使 ODP.NET 工作,您需要此处列出的软件(包括 oracle 客户端):http: //www.oracle.com/technology/tech/windows/odpnet/faq.html#install

Hope this helps!

希望这可以帮助!

回答by tuinstoel

I think odbc is too slow. System.Data.OracleClient is a bit slow too and it will be deprecated by Microsoft.

我认为 odbc 太慢了。System.Data.OracleClient 也有点慢,微软会弃用它。

You could use devart's provider, there is a free version. It is easy to deploy. See here http://www.devart.com/dotconnect/oracle/It does support the entity framework.

您可以使用 devart 的提供程序,有一个免费版本。很容易部署。看这里http://www.devart.com/dotconnect/oracle/它确实支持实体框架。

Odp.net is fast but it doesn't support the entity framework and it isn't very easy to deploy.

Odp.net 速度快,但不支持实体框架,部署也不是很方便。

回答by Ilya Khaprov

Maybe I'm wrong but ADO.NET have integrated support for Oracle. maybe for earlier versions...

也许我错了,但 ADO.NET 集成了对 Oracle 的支持。也许对于早期版本...

回答by Ucodia

I really cannot say the differences between the solutions you provided but I always used the Oracle Data Access Components from Oracle and it always worked flawlessly. It could be found here : ODAC for Visual Studio

我真的无法说出您提供的解决方案之间的差异,但我总是使用 Oracle 的 Oracle 数据访问组件,并且它始终可以完美运行。可以在这里找到:ODAC for Visual Studio

What is sure is that a library developped by Oracle on the .NET Framework will be much more accurate than a library developped by an company external to Oracle. For example, concerning exceptions thrown when accessing an Oracle database, they will be much more helpful if the library have been developped by the Oracle developping team as they have additional knowledges on Oracle DBs.

可以肯定的是,Oracle 在 .NET Framework 上开发的库将比 Oracle 外部公司开发的库准确得多。例如,关于访问Oracle数据库时抛出的异常,如果该库是由Oracle开发团队开发的,因为他们对Oracle DB有额外的了解,它们会更有帮助。

The bad thing is that you will have a dependency, problem that you will not have to overcome if you chose to use the .NET System.Data.OracleClient.

不好的是,如果您选择使用 .NET System.Data.OracleClient,您将有一个依赖项,您将不必克服这些问题。

Hope this helps. Regards.

希望这可以帮助。问候。



EDIT : The ODAC package contains ODP and Oracle Developer Tools

编辑:ODAC 包包含 ODP 和 Oracle 开发人员工具

回答by user196892

ODP.NET is a native provider fo accessing oracle db. And hence it should be better optimized for oracle db. Moreover, there are oracle feature, such as REF CURSOR type, which are not supported by MS ODBC, but supported by ODP.NET. You can download ODAC, which include ODP.NET as well, on the www.aracle.com website.

ODP.NET 是访问 oracle db 的本机提供程序。因此它应该更好地针对 oracle db 进行优化。此外,还有一些oracle 特性,例如REF CURSOR 类型,MS ODBC 不支持,但ODP.NET 支持。您可以在 www.aracle.com 网站上下载 ODAC,其中也包括 ODP.NET。