Simple example of C# program accessing Oracle

Nothing big, just a placeholder for an example of what is in the subject line.

//C:\Users\showard>C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe  /r:"C:\oracle\product\11.2.0\client_1\ODP.NET\bin\2.x\Oracle.DataAccess.dll" checkConn.cs

using System;
using Oracle.DataAccess.Client; 

public class checkConn {
  public static void Main(String []args){
    OracleConnection conn = new OracleConnection("User Id=biztalk;Password=********;Data Source=fn9dev");
    OracleDataReader rdr;
    try {
      conn.Open();
      OracleCommand cmd = new OracleCommand("select sysdate from dual", conn);
      rdr = cmd.ExecuteReader();
      while (rdr.Read())
        Console.WriteLine("Server time is " + rdr[0]);
      conn.Dispose();
    }
    catch(Exception e) {
      Console.WriteLine(e);
    }
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.