Tuesday 7 June 2016

Connecting Oracle Database in C#

In this course, you will explore how an Oracle Database applies ‘grid computing’ to multiple computers to provide fast, efficient, secure data storage and manipulation that easily scales to thousands of clients. You will learn how to install, administer, and maintain an Oracle 10g or 11g database in an effective and efficient manner. You will cover the interaction among Oracle components, Oracle’s architecture, and user management. Performance monitoring, database security, and backup and recovery techniques are covered. This course will assist those preparing to take the Oracle Certified Associate certification examination.


With a specific end goal to appropriately utilize the data contained in this article, I am going to accept the accompanying:

You have no less than a fundamental comprehension of C# and have composed code in it or some other dialect, for example, C++ or Java.

You have a fundamental comprehension of composing SQL orders.

Have an Oracle database to associate with.

On the off chance that your database is at your work environment, a duplicate of tsanames.ora gave by the DB administrator or whomever. (What's more, ideally, consent to get to the database!)

So with no further presentation, let me get into a little foundation.

What you require? 

You should make a free record on Oracle's webpage (beneath) and consent to their terms to have the capacity to download the customer.

Download Oracle Instant Client for Microsoft Windows (32-bit) here. There are different stages accessible, and a 64-bit rendition for Windows, yet I haven't took a gander at the substance of any of those and they are outside the extent of this report at any rate.

There are two adaptations you can browse. They are: Basic and Basic-Lite. I suggest getting the Basic Lite rendition, unless you have to bolster more than the English dialect.

OCCI requires just four element join libraries to be stacked by the dynamic loader of the Operating System. When this article was composed, it is utilizing the 10.2 rendition.

They are as per the following:

OCI Instant Client Data Shared Library

oraociicus10.dll (Basic-Lite form)

oraociei10.dll (Basic form)

Customer Code Library

oci.dll

Security Library

orannzsbb10.dll

OCCI Library

oraocci10.dll

// This really didn't need to be in its own method, but it makes it easier 
// to make changes if you want to try different things such as
// promting the user for credentials, etc.
static private string GetConnectionString() 
{ 
   // To avoid storing the connection string in your code, 
   // you can retrieve it from a configuration file. 
   return "Data Source=myserver.server.com;Persist Security Info=True;" + 
          "User ID=myUserID;Password=myPassword;Unicode=True"; 
}

// This will open the connection and query the database
static private void ConnectAndQuery() 
{ 
  string connectionString = GetConnectionString(); 
  using (OracleConnection connection = new OracleConnection()) 
  { 
    connection.ConnectionString = connectionString; 
    connection.Open(); 
    Console.WriteLine("State: {0}", connection.State); 
    Console.WriteLine("ConnectionString: {0}", 
                      connection.ConnectionString); 
    
    OracleCommand command = connection.CreateCommand(); 
    string sql = "SELECT * FROM MYTABLE"; 
    command.CommandText = sql; 
 
    OracleDataReader reader = command.ExecuteReader(); 
    while (reader.Read()) 
    { 
      string myField = (string)reader["MYFIELD"]; 
      Console.WriteLine(myField); 
    }
  }
}

No comments:

Post a Comment