daily pastebin goal
56%
SHARE
TWEET

Untitled

a guest Jan 21st, 2019 390 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private static string GetConnectionString()
  2.     {
  3.         String connString = "host= serverName;database=myDatabase;uid=userName;pwd=passWord";
  4.         return connString;
  5.     }
  6.  
  7.  private static void ConnectingToOracle()
  8.     {
  9.         string connectionString = GetConnectionString();
  10.         using (OracleConnection connection = new OracleConnection())
  11.         {
  12.             connection.ConnectionString = connectionString;
  13.             connection.Open();
  14.             Console.WriteLine("State: {0}", connection.State);
  15.             Console.WriteLine("ConnectionString: {0}",
  16.                               connection.ConnectionString);
  17.  
  18.             OracleCommand command = connection.CreateCommand();
  19.             string sql = "SELECT * FROM myTableName";
  20.             command.CommandText = sql;
  21.  
  22.             OracleDataReader reader = command.ExecuteReader();
  23.             while (reader.Read())
  24.             {
  25.                 string myField = (string)reader["MYFIELD"];
  26.                 Console.WriteLine(myField);
  27.             }
  28.         }
  29.     }
  30.    
  31. using System;
  32. using Oracle.DataAccess.Client;
  33. class OraTest
  34. {
  35. OracleConnection con;
  36. void Connect()
  37. {
  38. con = new OracleConnection();
  39. con.ConnectionString = "User Id=<username>;Password=<password>;Data Source=<datasource>";
  40. con.Open();
  41. Console.WriteLine("Connected to Oracle" + con.ServerVersion);
  42. }
  43. void Close()
  44. {
  45. con.Close();
  46. con.Dispose();
  47. }
  48. static void Main()
  49. {
  50. Example OraTest= new OraTest();
  51. OraTest.Connect();
  52. OraTest.Close();
  53. }
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top