0
votes

I do not understand why I have this error message. No code is used for the connection, only an SQLDatasource and a grid view. I am using this code:

protected void Page_Load(object sender, EventArgs e)

{
     try
    {
        using(OracleConnection conn = new OracleConnection("....."))
        using(OracleCommand cmd = new OracleCommand("select * from t1", conn))
        {
            conn.Open();
            using(OracleDataReader reader = cmd.ExecuteReader())
            {
                 DataTable dataTable = new DataTable();
                 dataTable.Load(reader);
                 ListBox1.DataSource = dataTable;
            }
        }
    }
    catch (Exception ex)
    {
        Label1.Text=ex.Message;
    }
}

enter image description here

2
Can you share the code - Baskar Rao
I've edited your question to inline the image, but you really should type the text in the error message rather than posting an image. That way, others searching can find the relevant words in your error. - Wai Ha Lee
Here is the code I am using: - Alcor

2 Answers

-1
votes

You can't use SqlConnection for the Oracle! First of all, you have to add connectionString into web.config to connection with Oracle. Secondly, Add reference System.Data.OracleClient to your project. Then, replace SqlConnection with OracleConnection. Everything, what you used with Sql, you have to replace with Oracle.

0
votes
  1. First you have install oracle data access client and then try this following code

    • protected void Button1_Click(object sender, EventArgs e) { string connectionString = "Data Source = DESCRIPTION = " + "(ADDRESS = (PROTOCOL = TCP)(HOST = ho

      • List item st_name)(PORT = 1521))" + "(CONNECT_DATA =" + " (SERVER = DEDICATED)" + " (SERVICE_NAME = your_service_name)" + ")" + ");User Id = ID;Password=Password;"; Oracle.DataAccess.Client.OracleConnection con = new Oracle.DataAccess.Client.OracleConnection(); con.ConnectionString = connectionString; con.Open(); Oracle.DataAccess.Client.OracleCommand cmd = new Oracle.DataAccess.Client.OracleCommand(); cmd.CommandText = "select ref_no from money_trn where ref_no=20170733"; cmd.Connection = con; con.Close(); cmd.CommandType = System.Data.CommandType.Text; Oracle.DataAccess.Client.OracleDataReader dr = cmd.ExecuteReader(); dr.Read(); TextBox1.Text = dr.GetString(0); }