Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> How to connect to an Oracle DB in .NET
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 AlfonsoReceived on Fri Feb 20 2004 - 03:21:48 CST