How to connect to an Oracle database from .NET?
Start using Oracle as the database from .NET with this simple Oracle connectivity tip.
Connecting to a SQL Server database from any .NET application is as simple as ABC. But when it comes to connecting to Oracle databases it’s not as simple as you think.
If you have access to the TNS file (tnsnames.ora) then you can pull out most of the information that you need to connect to an Oracle database. If you don’t have access to the TNS file then you need to gather these information prior to making an attempt to connect to an Oracle database,
· Database Name
· Primary TCP Host IP Address
· Primary TCP Port Number
· Secondary TCP Host IP Address
· Secondary TCP Port Number
· Oracle Service Name
· User ID
· Password
Once you have the above information you can then update your web.config file’s
Once you have these setup then it becomes ABC to really connect to the database. If you are using ODP.NET then you can use a similar statement like below to establish a connection to the Oracle database,
using Oracle.DataAccess.Client;
private string connString = ConfigurationManager.ConnectionStrings["databaseName"].ConnectionString;
try
{
OracleConnection conn = new OracleConnection();
conn.ConnectionString = connString;
conn.Open();
return conn;
}
catch (Exception ex)
{
// handle the generic exception if you wish
}
Keep in mind that the databaseName is nothing but the name given to the connection string on web.config.
Technorati Tags:
How To, .NET, Programming, Oracle, Oracle Connectivity


