ASP.NET Connection with Oracle DB

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;
    }
}

Answers


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.


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

Need Your Help

Netvibes like "draggable boxes" with javascript

jquery windows draggable dockable

Do you know any project/framework in javascript (jquery or anything else) that has nice draggable windows that snaps in some fixed places like netvibes has? I found jPolite v2 but it seems a little...

Is there a way to suppress duplicate merge module adding for an InstallShield 2012 project?

visual-studio-2010 installshield team-build installshield-2012

I have a visual studio solution with > 100 projects, the majority of them are different device "interface"/adapter dll's but there are also a few common dll's and applications. All are c# projects....