Connect to an Oracle server : Oracle « Database ADO.net « C# / C Sharp






Connect to an Oracle server

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

class OracleConnect
{
   static void Main() 
   {
      string connString = @"server = myServer;uid = scott;password = tiger;";

      OracleConnection conn = new OracleConnection(connString);

      try 
      {
         conn.Open();
         Console.WriteLine("Connection opened.");

         Console.WriteLine("Connection Properties:");   
         Console.WriteLine("\tConnection String: {0}", conn.ConnectionString);    
         Console.WriteLine("\tServerVersion: {0}", conn.ServerVersion);
         Console.WriteLine("\tState: {0}", conn.State);
      } catch (OracleException e) {
         Console.WriteLine("Error: " + e);  
      } finally {
         conn.Close();
         Console.WriteLine("Connection closed.");
      }
   }
}



           
         
  








Related examples in the same category

1.How to use an OleDbConnection object to connect to an Oracle database
2.Oracle connection string for C#
3.Static Helper for executing SQL statements against Oracle Requires the ODP.NET provider