Connect from .NET to Oracle without installing the Oracle Client

Scenario you support an application that connects to MS SQL, Oracle, DB2, and so on and so forth. You may or may not use an ORM and or you just want to connect directly to the database. You do not want to use up the resources by installing the full Oracle client.

What do you need to accomplish this?

A .NET project

Download the ODAC xcopy version (as of this article the latest was 11.2.0.2.1)

Copy the following dll’s from the ODAC folder to either the bin (if web) or location of the exe file

  • oci.dll (Client Code Library)
  • ociw32.dll
  • Oracle.DataAccess.dll
  • orannzsbb11.dll (Security Library)
  • oraocci11.dll (OCCI Library)
  • oraociei11.dll (OCI Instant Client Data shared Library)
  • OraOps11w.dll

You can create your tsanames.ora from either code or in web.config

string Connstring = "Data Source=(DESCRIPTION=" +
   "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)" +
   "(HOST=serverName)" +
   "(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)" +
   "(SERVICE_NAME=DatabaseName)));" +
   "User Id=UserName;Password=UserPassword;";

Then just create your open connection like normal

Here is an example solution.

OracleTest.zip

Advertisement
This entry was posted in Database and tagged . Bookmark the permalink.

7 Responses to Connect from .NET to Oracle without installing the Oracle Client

  1. nbarger says:

    Thanks Chad, this saved us a bit of research (and by research, I mean trial and error) 🙂

  2. Abrham Smith says:

    Damn, do you still have your source file?

  3. Charbel Obeidi says:

    Hi, can you upload the oarcletest.zip again?

  4. lssilveira says:

    Maybe you can set TNSADMIN environment variable to a tnsadmin.ora file, put an entry in that file and references that on connection string of web.config file.

  5. kumar says:

    It is very usefull

  6. Alejo says:

    OracleTest.zip don’t exists! 😦

Comments are closed.