Start New Discussion within our Web Development Community

I have the following code for connecting to an Oracle DB

using Oracle.DataAccess.Client; // C# ODP.NET Oracle managed provider

OraDb=
  (DESCRIPTION=
    (ADDRESS_LIST=
      (ADDRESS=(PROTOCOL=TCP)(HOST=ORASRVR)(PORT=1521))
    )
    (CONNECT_DATA=
      (SERVER=DEDICATED)
      (SERVICE_NAME=ORCL)
    )
  )



string oradb = "Data Source=//192.168.100.108;User Id=hr;Password=hr;"; // C#

string oradb = "Data Source=(DESCRIPTION="
             + "(ADDRESS=(PROTOCOL=TCP)(HOST=ORASRVR)(PORT=1521))"
             + "(CONNECT_DATA=(SERVICE_NAME=ORCL)));"
             + "User Id=hr;Password=hr;";
OracleConnection conn = new OracleConnection(oradb); // C#
OracleConnection conn = new OracleConnection(); // C#
conn.ConnectionString = oradb;

conn.Open(); // C#

string sql = " select department_name from departments where department_id = 10"; // C#
OracleCommand cmd = new OracleCommand(sql, conn);
cmd.CommandType = CommandType.Text;

conn.Close();   // C#
conn.Dispose(); // C#

but its not working. Any suggestions?

This article has been dead for over six months. Start a new discussion instead.