locked
Oracle database connection data access from C#

    Question

  • Hi all, 

    I am new to Oracle database accessing from C#.

    I am trying to access the database of a oracle database named "orcl"  from C#.

    There is a problem in connection open. The following is the code I have written under a click button:--

    string oradb = "Data Source=orcl ; User Id=sysman ;Password=abc123;"; 
     /* CODE           

                //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); 

                conn.Open();  //Open the Connection

                //Command Object 
                string sql = " select EMP_NAME from EMP where EMP_ID=1"; // sql query 
                OracleCommand cmd = new OracleCommand(sql, conn);
                cmd.CommandType = CommandType.Text;

                // Retrieving a Scalar Value 
                OracleDataReader dr = cmd.ExecuteReader(); 
                dr.Read();

                label1.Text = dr["EMP_NAME"].ToString();            // retrieve by column name
                label1.Text = dr.GetString(0).ToString();           // return a .NET data type
                label1.Text = dr.GetOracleString(0).ToString();     // return an Oracle data type

                conn.Close();
                conn.Dispose();

    */

    I am getting  the following exception

    "An unhandled exception of type 'Oracle.DataAccess.Client.OracleException' occurred in Oracle.DataAccess.dll

    Additional information: External component has thrown an exception."

    Please help me to solve the problem.....

    Thank you all in advance

    ItsmePMB

    Monday, July 09, 2012 4:24 AM

Answers

All replies