This discussion is archived
12 Replies Latest reply: Nov 2, 2011 11:18 AM by user13328581 RSS

oracle connection problem...

user13328581 Explorer
Currently Being Moderated
dear all;

I have the following syntax below
 protected void Button1_Click(object sender, EventArgs e)
    {

 string oradb = "User Id=finance;Password=finace1;Data Source=XE";
        string sql = "select ID, Create_date from t_mobile";
        OracleDataAdapter adapter = new OracleDataAdapter(oradb, sql);
        OracleCommandBuilder builder = new OracleCommandBuilder(adapter);

        DataSet dataset = new DataSet();

        adapter.Fill(dataset, "t_mobile");

        DataTable mytable = dataset.Tables["t_mobile"];

        GridView1.DataSource = mytable;
        GridView1.DataBind();
    }
but I keep getting the error message connection not well formatted, how I do connect to my sql*plus using visual web developer 2010 express for practicing purposes. thank you. a simple code example will also help
  • 1. Re: oracle connection problem...
    890764 Newbie
    Currently Being Moderated
    Here are a couple of connection string used to connect to Oracle. http://www.connectionstrings.com/oracle See if this will solve your problem. I think the first one will work for you.

    *[url http://www.java-forums.org/blogs/advanced-java/collection/]Java collection*
  • 2. Re: oracle connection problem...
    user13328581 Explorer
    Currently Being Moderated
    that didnt work...
  • 3. Re: oracle connection problem...
    user13328581 Explorer
    Currently Being Moderated
    OK i am a little progress, now the only error is connection is not open unfortunately
      DataTable emptable = new DataTable();
            string oradb = "Data Source = (DESCRIPTION ="
        + "(ADDRESS_LIST=(ADDRESS = (PROTOCOL = TCP)(HOST = olisa-VAIO)(PORT = 1521)))"
        + "(CONNECT_DATA= (SERVER = DEDICATED)(SERVICE_NAME = XE)));"
        + "User Id = finance; Password=financecc;";
            OracleConnection conn = new OracleConnection(oradb);
            conn.Open();
            string sql = "select ID, Create_date from t_mobile";
            OracleCommand cmd = new OracleCommand(sql, conn);
            cmd.CommandType = CommandType.Text;
            emptable.Load(cmd.ExecuteReader());
            GridView1.DataSource = emptable;
            GridView1.DataBind();
    
            conn.Close();
            conn.Dispose();
    Edited by: user13328581 on Oct 5, 2011 5:59 PM
  • 4. Re: oracle connection problem...
    890764 Newbie
    Currently Being Moderated
    Can you please provide the error log? Thanks.
  • 5. Re: oracle connection problem...
    user13328581 Explorer
    Currently Being Moderated
    i get the following error, ORA-6413: Connection not open.
  • 6. Re: oracle connection problem...
    890764 Newbie
    Currently Being Moderated
    Are you sure all the Parameters are OK?
    To make sure of that, if you use SQL Developer, right click on your connection (assuming you have one that works), then select TNS as Connection Type, then click Connection Identifier to enable the text-field, and copy the connection string from there.

    PS: Make sure there is no firewall that might block your connection, or the database accepts remote connections.
  • 7. Re: oracle connection problem...
    user13328581 Explorer
    Currently Being Moderated
    i am using sql plus unfortunately, how do you apply such a check in sql plus
  • 8. Re: oracle connection problem...
    890764 Newbie
    Currently Being Moderated
    I really don't know that, as I worked with it just a little, but use the same settings as you used when you set it up, or ask the one who did if it weren't you. Or there is anyone else here who knows how to do it. :)
  • 9. Re: oracle connection problem...
    user13328581 Explorer
    Currently Being Moderated
    I use pl/sql developer at work and my connections works fine there but i am trying to use a free sql tool which is sql*plus and things arent just working and i am trying to figure out why
  • 10. Re: oracle connection problem...
    890764 Newbie
    Currently Being Moderated
    Can you post the connection settings from you sql developer? (nothing confidential - you can mask the user/pass/host) as I need to see what type it is.
  • 11. Re: oracle connection problem...
    user13328581 Explorer
    Currently Being Moderated
    where am I going to get that information from or what exactly do you mean?
  • 12. Re: oracle connection problem...
    user13328581 Explorer
    Currently Being Moderated
    I finally got it working all...here is the simple solutions. First and foremorst, make sure you are using the right various of sql*plus because I noticed for visual studio 2010 express, it is only compatible with Oracle Database Express Edition 11g Release 2, don't know why but I tired oracle 10g and that didnt work. Oracle Database Express Edition 11g Release 2 can be found at the following link below.

    http://www.oracle.com/technetwork/database/express-edition/downloads/index.html

    the next step is to download the right drivers to establish the connection which can found at the following link below

    http://www.oracle.com/technetwork/developer-tools/visual-studio/downloads/index.html and the name of the driver is ODAC 11.2 Release 3 (11.2.0.2.1) with Oracle Developer Tools for Visual Studio. That is the right driver for oracle 11g for asp.net 4.0.

    Once the driver has been downloaded, it is time to write a simple program. An example is shown below
    protected void Button1_Click(object sender, EventArgs e)
        {
           DataTable emptable = new DataTable();
           string oradb = "Data Source=(DESCRIPTION ="
            + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=olisa-VAIO)(PORT=1521)))"
            + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XE)));"
            + "User Id = finance; Password=financecc;";
           OracleConnection conn = new OracleConnection(oradb);
           conn.Open();
           string sql = "select ID, Create_date from t_mobile";
           OracleCommand cmd = new OracleCommand(sql, conn);
           cmd.CommandType = CommandType.Text;
           emptable.Load(cmd.ExecuteReader());
           GridView1.DataSource = emptable;
           GridView1.DataBind();
    
           conn.Close();
           conn.Dispose();
    
        }
    notice that you will need the right oracle .dll to establish the connection, this can be done by adding a reference, in the reference section click on browser and navigate to the following directory to add the oracle.dataaccess.dll. the path is %ORACLE_HOME%\odp.net\bin\<version>\Oracle.DataAccess.dll and you should be set to go. Notice, you are doing it this way because there is currently a bug with the latest driver.

    Edited by: user13328581 on Nov 2, 2011 11:17 AM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points