71

I have successfully connected to an Oracle database (10g) from C# (Visual Studio 2008) by downloading and installing the client administration tools and Visual Studio 2008 on my laptop.

The installation footprint for Oracle Client tools was over 200Mb, and quite long winded.

Does anyone know what the minimum workable footprint is? I am hoping that it's a single DLL and a register command, but I have the feeling I need to install an oracle home, and set various environment variables.

I am using Oracle.DataAccess in my code.

Jonathan
  • 25,873
  • 13
  • 66
  • 85
  • 22
    As Oracle newbie, it was a nightmare also for me finding and installing all the right components and libraries I needed. I cannot understand, how Oracle couldn't provide such "mediocre" support to .NET developers... – splattne Jan 01 '09 at 12:44
  • @ecoe Thanks for revisiting this question. Your answer http://stackoverflow.com/a/26469797/6910 seems to be the smallest footprint so far. – Jonathan Oct 21 '14 at 07:47
  • 4
    @splattne: Don't feel bad, Oracle provides mediocre software to all developers and customers. – Charles Burns May 13 '15 at 21:33

8 Answers8

71

You need an Oracle Client to connect to an Oracle database. The easiest way is to install the Oracle Data Access Components.

To minimize the footprint, I suggest the following :

  • Use the Microsoft provider for Oracle (System.Data.OracleClient), which ships with the framework.
  • Download the Oracle Instant Client Package - Basic Lite : this is a zip file with (almost) the bare minimum. I recommend version 10.2.0.4, which is much smaller than version 11.1.0.6.0.
  • Unzip the following files in a specific folder :
    • v10 :
      • oci.dll
      • orannzsbb10.dll
      • oraociicus10.dll
    • v11 :
      • oci.dll
      • orannzsbb11.dll
      • oraociei11.dll
  • On a x86 platform, add the CRT DLL for Visual Studio 2003 (msvcr71.dll) to this folder, as Oracle guys forgot to read this...
  • Add this folder to the PATH environment variable.
  • Use the Easy Connect Naming method in your application to get rid of the infamous TNSNAMES.ORA configuration file. It looks like this : sales-server:1521/sales.us.acme.com.

This amounts to about 19Mb (v10).

If you do not care about sharing this folder between several applications, an alternative would be to ship the above mentioned DLLs along with your application binaries, and skip the PATH setting step.

If you absolutely need to use the Oracle provider (Oracle.DataAccess), you will need :

  • ODP .NET 11.1.0.6.20 (the first version which allegedly works with Instant Client).
  • Instant Client 11.1.0.6.0, obviously.

Note that I haven't tested this latest configuration...

Mac
  • 8,191
  • 4
  • 40
  • 51
  • 1
    using Visual Studio 2005, I have had success without performing steps 4 or 5 – Timothy Carter Sep 16 '08 at 10:58
  • Is it ok to just include the dlls with your app in terms of licensing? – thecoop Dec 04 '09 at 13:18
  • Instant Client is licensed under the OTN Development and Distribution License (cf. http://www.oracle.com/technology/software/htdocs/client_lic.html). Which means you can freely redistribute it with your application (cf. http://www.oracle.com/technology/tech/oci/instantclient/ic-faq.html#A4379). – Mac Dec 07 '09 at 10:29
  • 5
    Using ODAC version 11.2.0.1.2 installed solely on my development machine, I was able to deploy by copying oci.dll, Oracle.DataAccess.dll, oraociei11.dll, and OraOps11w.dll. I didn't have to install ANYTHING on the production machine, which was awesome. My development machine is Win7 x64 and I tested production on a vanilla WinXP x86 VM (.NET Framework and not much else). – Pandincus Dec 28 '10 at 18:47
  • 1
    Using the Instant Client Lite and copying all the DLLs to the application folder on my destination machine along with Oracle.DataAccess.dll and using an Easy Connection connection string allowed me to use the full Oracle client on my development machine and then just copy those DLLs when I deploy and the same binary works in both cases – cjbarth Sep 13 '11 at 14:19
  • Microsoft provider `System.Data.OracleClient` is [deprecated](https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/oracle-and-adonet) for ages, you should not use it anymore. – Wernfried Domscheit May 07 '18 at 07:54
15

As of 2014, the OPD.NET, Managed Driver is the smallest footprint.

Here is a code usage comparison to the non-managed versions that previous (outdated) answers suggested: http://docs.oracle.com/cd/E51173_01/win.122/e17732/intro005.htm#ODPNT148

You will need to download these dlls and reference Oracle.ManagedDataAccess.dll in your project: Download the ODP.NET, Managed Driver Xcopy version only

Here is a typical foot print you will need to package with your release:

  1. Oracle.ManagedDataAccess.dll
  2. Oracle.ManagedDataAccessDTC.dll

all together, a whopping 6.4 MB for .Net 4.0.

ecoe
  • 4,994
  • 7
  • 54
  • 72
  • You can download `Oracle.ManagedDataAccess.dll` via NuGet as well. – Ragowit Mar 02 '15 at 13:59
  • +1000 Simplest solution; notice the "using Oracle.ManagedDataAccess.Client;" – Nime Cloud Jun 09 '15 at 08:04
  • No tnsnames.ora, sqlnet.ora, registry settings or environment variables needed to use Oracle.ManagedDataAccess.dll if you use the "ODP.NET without tnsnames.ora" technique in the connection string described here: https://www.connectionstrings.com/oracle-data-provider-for-net-odp-net/ – mchestnut Nov 13 '15 at 14:46
  • There's no .Net 3.5 alternative though. Stuck on an ancient 3.5 project. Trying to use this on 3.5 just fails the compile with a `namespace name 'Oracle' could not be found` error. – Nyerguds Dec 30 '21 at 12:44
15

I use the method suggested by Pandicus above, on Windows XP, using ODAC 11.2.0.2.1. The steps are as follows:

  1. Download the "ODAC 11.2 Release 3 (11.2.0.2.1) with Xcopy Deployment" package from oracle.com (53 MB), and extract the ZIP.
  2. Collect the following DLLs: oci.dll (1 MB), oraociei11.dll (130 MB!), OraOps11w.dll (0.4 MB), Oracle.DataAccess.dll (1 MB). The remaining stuff can be deleted, and nothing have to be installed.
  3. Add a reference to Oracle.DataAccess.dll, add using Oracle.DataAccess.Client; to your code and now you can use types like OracleConnection, OracleCommand and OracleDataReader to access an Oracle database. See the class documentation for details. There is no need to use the tnsnames.ora configuration file, only the connection string must be set properly.
  4. The above 4 DLLs have to be deployed along with your executable.
kol
  • 27,881
  • 12
  • 83
  • 120
14

This way allows you to connect with ODP.net using 5 redistributable files from oracle:

Chris's blog entry: Using the new ODP.Net to access Oracle from C# with simple deployment

Edit: In case the blog every goes down, here is a brief summary...

  • oci.dll
  • Oracle.DataAccess.dll
  • oraociicus11.dll
  • OraOps11w.dll
  • orannzsbb11.dll
  • oraocci11.dll
  • ociw32.dll

make sure you get ALL those DLL's from the same ODP.Net / ODAC distribution to avoid version number conflicts, and put them all in the same folder as your EXE

Danny Varod
  • 17,324
  • 5
  • 69
  • 111
Fidel
  • 7,027
  • 11
  • 57
  • 81
  • The article says "No TnsNames.Ora file needed"... but that just means it can't translate database names. – Nyerguds Oct 09 '17 at 12:39
8

DevArt http://www.devart.com/, formerly CoreLab (crlab.com) supplies a pure-C# Oracle client. That's a single dll, and it works fine.

  • That's very close to what I want, actually. Ideally, I'd like an Oracle only solution, but I am investigating this one. – Jonathan Sep 16 '08 at 09:56
  • And it does not require a local Oracle Client installation? – Ishmaeel Sep 16 '08 at 10:07
  • 1
    @Ishmaeel It has a "direct" mode that does not require an Oracle client to be installed on the target machine. – Adam Jul 16 '13 at 10:40
5

Here is an update for Oracle 11.2.0.4.0. I had success with the following procedure on Windows 7 using System.Data.OracleClient.

1. Download Instant Client Package - Basic Lite: Windows 32-Bit or 64-Bit.

2. Copy the following files to a location in your system path:

32-Bit

 1,036,288  2013-10-11  oci.dll
   348,160  2013-10-11  ociw32.dll
 1,290,240  2013-09-21  orannzsbb11.dll
   562,688  2013-10-11  oraocci11.dll
36,286,464  2013-10-11  oraociicus11.dll

64-Bit

   691,712  2013-10-09  oci.dll
   482,304  2013-10-09  ociw32.dll
 1,603,072  2013-09-10  orannzsbb11.dll
 1,235,456  2013-10-09  oraocci11.dll
45,935,104  2013-10-09  oraociicus11.dll

3. Construct a connection string that omits the need for tnsnames.ora.

(See examples in the test program below.)

4. Run this minimal C# program to test your installation:

using System;
using System.Data;
using System.Data.OracleClient;

class TestOracleInstantClient
{
    static public void Main(string[] args)
    {
        const string host = "yourhost.yourdomain.com";
        const string serviceName = "yourservice.yourdomain.com";
        const string userId = "foo";
        const string password = "bar";

        var conn = new OracleConnection();

        // Construct a connection string using Method 1 or 2.
        conn.ConnectionString =
            GetConnectionStringMethod1(host, serviceName, userId, password);

        try
        {
            conn.Open();
            Console.WriteLine("Connection succeeded.");
            // Do something with the connection.
            conn.Close();
        }
        catch (Exception e)
        {
            Console.WriteLine("Connection failed: " + e.Message);
        }
    }

    static private string GetConnectionStringMethod1(
        string host,
        string serviceName,
        string userId,
        string password
        )
    {
        string format =
            "SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)" +
            "(HOST={0})(PORT=1521))" +
            "(CONNECT_DATA=(SERVER=DEDICATED)" +
            "(SERVICE_NAME={1})));" +
            "uid={2};" +
            "pwd={3};"; // assumes port is 1521 (the default)

        return String.Format(format, host, serviceName, userId, password);
    }

    static private string GetConnectionStringMethod2(
        string host,
        string serviceName,
        string userId,
        string password
        )
    {
        string format =
            "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)" +
            "(HOST={0})(PORT=1521))" +
            "(CONNECT_DATA=(SERVER=DEDICATED)" +
            "(SERVICE_NAME={1})));" +
            "User Id={2};" +
            "Password={3};"; // assumes port is 1521 (the default)

        return String.Format(format, host, serviceName, userId, password);
    }
}

Final tip: If you encounter the error "System.Data.OracleClient requires Oracle client software version 8.1.7", see this question.

Community
  • 1
  • 1
DavidRR
  • 18,291
  • 25
  • 109
  • 191
  • It says: System.Data.OracleClient requires Oracle client software version 8.1.7 or greater. – Nime Cloud Jun 09 '15 at 06:59
  • @NimeCloud: One possibility is that this could be a **file system permissions** problem that is preventing your program from accessing the Oracle DLLs. See [this article](http://blogs.msdn.com/b/fabdulwahab/archive/2011/11/13/system-data-oracleclient-requires-oracle-client-software-version-8-1-7-or-greater.aspx) and [this one](https://social.technet.microsoft.com/Forums/sqlserver/en-US/30c5d7e4-0dc6-4e8e-8d9a-0d9d8555bd51/systemdataoracleclient-requires-oracle-client-software-version-817-or-greater-while-attempting?forum=sqlreportingservices). – DavidRR Jun 09 '15 at 12:15
3

ODAC xcopy will get you away with about 45MB. http://www.oracle.com/technology/software/tech/windows/odpnet/index.html

2

I found this post on the Oracle forum very usefull as well:

How to setup Oracle Instant Client with Visual Studio

Remark: the ADO.NET team is deprecating System.Data.OracleClient so for future projects you should use ODP.NET

Reproduction:

Setup the following environment variables:

  1. make sure no other oracle directory is in your PATH
  2. set your PATH to point to your instant client
  3. set your TNS_ADMIN to point to where you tnsnames.ora file is located
  4. set your NLS_LANG
  5. set your ORACLE_HOME to your instant client

For me, I set NLS_LANG to

http://download-east.oracle.com/docs/html/A95493_01/gblsupp.htm#634282

I verified this was using the correct client software by using the sqlplus add-on to the instant client.

For me, I set: SET NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252

Note: before you make any changes, back up your Oracle registry key (if exist) and backup the string for any environment variables.

Read the Oracle Instant Client FAQ here

Community
  • 1
  • 1
Vincent De Smet
  • 4,859
  • 2
  • 34
  • 41