简体   繁体   中英

Connecting C# to Oracle

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

  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. ?

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?

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:

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?

Edit 2:
I am using .Net 3.5

Microsoft will deprecate the System.Client.OracleClient namespace 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.

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

  • ODP.Net (Oracle)
  • System.Data.OracleClient (Microsoft)
  • ODBC (Oracle)
  • OLEDB (Oracle)
  • DataDirect ADO.NET Data Provider for Oracle (DataDirect)
  • may be some other provider

All of 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:

  • 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 client is provided in different packages. This is the smallest way for deployment of an oracle client.

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

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

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

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:

  • 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.

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

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

Hope this helps!

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

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

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.

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

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

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.

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.

Hope this helps. Regards.


EDIT : The ODAC package contains ODP and Oracle Developer Tools

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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