简体   繁体   English

将C#连接到Oracle

[英]Connecting C# to Oracle

What is the best library/driver to connect C# (.NET) application to Oracle 10g and 11g. 将C#(.NET)应用程序连接到Oracle 10g和11g的最佳库/驱动程序是什么。
Current options that I found are: 我找到的当前选项是:

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

Can somebody explain differences? 有人可以解释一下差异吗?

I am planning C# application that will do basic CRUD operations on Oracle database. 我正在计划将在Oracle数据库上执行基本CRUD操作的C#应用​​程序。 Which library/driver is smallest and easiest to install? 哪个库/驱动程序最小且最容易安装?

Edit: 编辑:
General recommendation is to use ODP.Net. 一般建议是使用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: 我为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. Oracle文档非常详细,但没有说明这些客户端软件包之间的差异。 I would go with smallest (Instant Client). 我会选择最小的(即时客户端)。 Is it best choice? 这是最好的选择吗?

Edit 2: 编辑2:
I am using .Net 3.5 我正在使用.Net 3.5

Microsoft will deprecate the System.Client.OracleClient namespace so I think it will be best to use ODP.NET . Microsoft将弃用 System.Client.OracleClient命名空间,因此我认为最好使用ODP.NET Make sure you download the latest one (ODP.NET 11g) as previous versions had some issues. 确保下载最新版本(ODP.NET 11g),因为以前的版本存在一些问题。

To connect C# to oracle you need a data provider for .net. 要将C#连接到oracle,您需要.net的数据提供程序。 This can be one of the following: 这可以是以下之一:

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

All of this data provider need an oracle client installed. 所有这些数据提供者都需要安装oracle客户端。 There is no standalone library as jdbc14.jar as in java. 没有独立的库作为jdbc14.jar,就像在java中一样。 You have 2 choices deploying an oracle client: 您有2个选择部署oracle客户端:

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

ODP.Net, ODBC, OLEDB are part of full client. ODP.Net,ODBC,OLEDB是完整客户端的一部分。 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 client is provided in different packages. 即时客户端以不同的包提供。 This is the smallest way for deployment of an oracle client. 这是部署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) 选择版本11.1.0.6.0(或提供ODAC的更新版本)
  • Instant Client Package - Basic (if you need full language support) Instant Client Package - 基本(如果您需要完整的语言支持)
  • Instant Client Package - ODAC 即时客户端软件包 - ODAC

There are a lot of articles on stackoverflow about deployment of oracle instant client with c# applications. 关于使用c#应用程序部署oracle即时客户端的stackoverflow有很多文章。

EDIT: updated links and versions 编辑:更新的链接和版本

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数据库的最佳提供程序,主要是因为它是最本机的,它通过以下方式区别于ODBC:

  • better performance 更好的性能
  • ODP.NET provides access to advanced Oracle functionality, not available via ODBC .NET ODP.NET提供对高级Oracle功能的访问,而不是通过ODBC .NET提供
  • ODP.NET does not use an extra data access bridge. 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! 希望这可以帮助!

Maybe I'm wrong but ADO.NET have integrated support for Oracle. 也许我错了,但ADO.NET已经集成了对Oracle的支持。 maybe for earlier versions... 也许对于早期版本......

I think odbc is too slow. 我觉得odbc太慢了。 System.Data.OracleClient is a bit slow too and it will be deprecated by Microsoft. System.Data.OracleClient也有点慢,它将被Microsoft弃用。

You could use devart's provider, there is a free version. 你可以使用devart的提供者,有一个免费版本。 It is easy to deploy. 它易于部署。 See here http://www.devart.com/dotconnect/oracle/ It does support the entity framework. 请参见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速度很快,但它不支持实体框架,因此部署起来并不容易。

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. 我真的不能说你提供的解决方案之间的差异,但我总是使用Oracle提供的Oracle数据访问组件,它始终完美无瑕。 It could be found here : ODAC for Visual Studio 它可以在这里找到: 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. 可以肯定的是,Oracle在.NET Framework上开发的库比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数据库时抛出的异常,如果Oracle开发团队已经开发了这些库,那么它们会更有帮助,因为他们对Oracle数据库有额外的了解。

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 Developer Tools

ODP.NET is a native provider fo accessing oracle db. ODP.NET是访问oracle db的本机提供程序。 And hence it should be better optimized for oracle db. 因此它应该更好地优化oracle db。 Moreover, there are oracle feature, such as REF CURSOR type, which are not supported by MS ODBC, but supported by ODP.NET. 此外,还有oracle特性,例如REF CURSOR类型,它们不受MS ODBC支持,但受ODP.NET支持。 You can download ODAC, which include ODP.NET as well, on the www.aracle.com website. 您也可以在www.aracle.com网站上下载ODAC,其中包括ODP.NET。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM