Connect To Oracle Database Server Without Oracle Client

Introduction

Let's have a look at the contents.

Contents

  • Oracle Database Server 
  • Oracle Client
  • Connect the Oracle Database Server 
  • Connect the Oracle Database server without Oracle client 
  • Developer Setup
  • Code
  • Server Deployment (Web server or Application Server)
  • Conclusion
An Oracle database is an object-relational database management system produced and marketed by the Oracle Corporation. It supports heterogeneous data. We can stack our data here.

It has the following two main parts:
  • Oracle Database Server
  • Oracle Client
Oracle Database Server

This is where your data is saved. A database server is the key to solving the problems of information management. In general, a server reliably manages a large amount of data in a multiuser environment so that many users can concurrently access the same data. All this is done while delivering high performance. A database server also prevents unauthorized access and provides efficient solutions for failure recovery.

Oracle Client

If you are connecting to an Oracle server from your application, then the Oracle clients help you to push and pull the data from the Oracle server database, in other words a piece of software that allows a remote computer to talk to Oracle. If you were to write a piece of software that communicates with the database, you would use the Oracle Client to facilitate that communication.

In other words, the Oracle client plays like a broker between your front-end application and the Oracle server database.

Connect the Oracle Database Server

There are many ways to connect to an Oracle database server but it should use the Oracle client.
  • ODBC
  • OLEDB
  • Service
Here the TNSNAMES.ora file plays the main role in the preceding scenario.

Connect to the Oracle Database Server without Oracle Client

This tool is about connecting to the database server without installing the Oracle client.
  • Download Oracle Data Access Components (ODAC) 11.2.0.1.2 - (xcopy version - ODAC112012Xcopy.zip). This component is available in the Oracle downloads.
  • Copy OraOps11w.dll found in the odp.net4/b in directory.
     
  • Copy oci.dll, orannzsbb11.dll and oraociicus11.dll found in the instantclient_11_2 directory.
     
  • Copy the Oracle.DataAccess.dll found in the odp.net4/odp.net/bin/4 directory.
Developer Setup

Place the preceding DLLs into your application's executable path.

Place the Oracle.DataAccess.dll in the GAC as in the following:
  1. C:\> gacutil /i “<Application Path>\ Oracle.DataAccess.dll”  
Be sure the assembly entry is available. (C:\Windows\assembly)

Add the Oracle.DataAccess.dll to your project.



Create the connection string as in the following sample.
  1. user id=USERID;word=WORD;data source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=IPorSERVERNAME) (PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ValidSID)))  
Code

Import the Oracle.DataAccess.Client into your source file. Build the ADO.Net code based on the ODAC reference.
  1. using System;  
  2. using Oracle.DataAccess.Client;   
  3.   
  4. namespace Sample  
  5. {  
  6.     class Program  
  7.     {  
  8.         static void Main(string[] args)  
  9.         {  
  10.             //You need to enter a valid Oracle connection   
  11.               
  12.             string connectionString =  
  13.                 "user id=USERID;word=WORD;" +  
  14.                 "data source=(DESCRIPTION=(ADDRESS=" +  
  15.                 "(PROTOCOL=tcp)(HOST=IPorSERVERNAME)" +  
  16.                 "(PORT=1521))(CONNECT_DATA=" +  
  17.                 "(SERVICE_NAME=ValidSID)))";  
  18.   
  19.             using (OracleConnection connection =  
  20.                 new OracleConnection())  
  21.             {  
  22.                 connection.ConnectionString =  
  23.                     connectionString;  
  24.   
  25.                 try  
  26.                 {  
  27.                     connection.Open();  
  28.                     Console.WriteLine  
  29.                         ("Connection Successful!");                      
  30.                     Console.ReadLine();  
  31.                 }  
  32.                 catch (OracleException ex)  
  33.                 {  
  34.                     Console.WriteLine(ex.ToString());                      
  35.                     Console.ReadLine();  
  36.                 }  
  37.             }  
  38.         }  
  39.     }  
  40. }  
Server Deployment (Web server or Application Server)
  • Place the Oracle.DataAccess.dll in the GAC.
  • Deploy your application with the preceding supporting libraries.
Conclusion

Now you have connected to the Oracle database server without an Oracle client.

Up Next
    Ebook Download
    View all
    Learn
    View all