Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> How to connect to an Oracle DB in .NET

How to connect to an Oracle DB in .NET

From: AVS <nor_at_nor.es>
Date: Fri, 20 Feb 2004 10:21:48 +0100
Message-ID: <4035D1AC.874B2943@nor.es>


Hi,

I´ve got it (arf, arf, ....)

This is the Connection String to connect to an Oracle DB in a remote server, in :NET:

ConnectionString = "Provider=msdaora;Data Source=MyOracleBD;Server=xxx.xxx.xxx.xxx;Port=yyyy;User ID=user_id;Password=password;"

So, a complete code to connect and get data from a DB would be:

public DataSet GetData()
{

    DataSet ds = new DataSet("Data");

    try
    {
    string command_string, connection_string;

    connection_string = "Provider=msdaora;Data Source=MyOracleBD;Server=xxx.xxx.xxx.xxx;Port=x;User ID=user_id;Password=password;"

    command_string = "SELECT column01,column02 FROM table WHERE condition";

    OleDbConnection conn = new OleDbConnection(connection_string);     conn.Open();

    //Apply Select
    OleDbDataAdapter adapter = new OleDbDataAdapter( command_string, conn);

    adapter.Fill(ds);

    //Close connection
    conn.Close();
}

catch(OleDbException oe)

   {
    string strerror;

    strerror = oe.Message;
    ds = null;
   }

    return ds;
}

//***********************************************

OK, I've not discovered America, but I was no able to find any thing in Inet (for a remote server case), and testing, testing... it worked!

--
Regards

Alfonso
Received on Fri Feb 20 2004 - 03:21:48 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US