Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

oracle connection problem...

user13328581Sep 15 2011 — edited Dec 13 2011
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

Comments

890764
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*
user13328581
that didnt work...
user13328581
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
890764
Can you please provide the error log? Thanks.
user13328581
i get the following error, ORA-6413: Connection not open.
890764
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.
user13328581
i am using sql plus unfortunately, how do you apply such a check in sql plus
890764
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. :)
user13328581
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
890764
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.
user13328581
where am I going to get that information from or what exactly do you mean?
user13328581
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
1 - 12
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Nov 30 2011
Added on Sep 15 2011
12 comments
5,714 views