How to connect c# with oracle

Solved/Closed
tedal - Feb 2, 2009 at 07:19 PM
 c00l - Aug 25, 2010 at 09:46 PM
is it must to have a privilege access to the computer to connect c# and oracle?

1 reply

using System;
using System.Data;
using System.Data.OleDb;

class OleDbConnectionOracle
{
public static void Main()
{
string connectionString = "provider=MSDAORA;data source=ORCL;user id=SCOTT;password=TIGER";
OleDbConnection myOleDbConnection = new OleDbConnection(connectionString);

OleDbCommand myOleDbCommand = myOleDbConnection.CreateCommand();

myOleDbCommand.CommandText = "SELECT empno, ename, sal FROM emp WHERE empno = 7369";

myOleDbConnection.Open();

OleDbDataReader myOleDbDataReader = myOleDbCommand.ExecuteReader();

myOleDbDataReader.Read();

Console.WriteLine("myOleDbDataReader[\" empno\"] = " + myOleDbDataReader["empno"]);
Console.WriteLine("myOleDbDataReader[\" ename\"] = " + myOleDbDataReader["ename"]);
Console.WriteLine("myOleDbDataReader[\" sal\"] = " + myOleDbDataReader["sal"]);

myOleDbDataReader.Close();
myOleDbConnection.Close();
}
}
30