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 section to reflect the below connection string (replace the entries appropriately, of course!)





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:
, , , , Oracle Connectivity

Related Posts with Thumbnails


Subscribe to our free RSS feed to keep up with what's happening at DemoGeek.com

At DemoGeek.com we try to explain the tech stuffs in as much detail as we can to help the not-so-tech-savvy of our friends understand and follow the tech stuffs.

Share/Save/Bookmark

Subscribe to DemoGeek.com

Leave a Reply





XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

2 Trackbacks/Pings

About DemoGeek.com

DemoGeek.com brings you high quality articles, tutorials and how to's on everything related to Microsoft Windows, Mac OSX, iPhone, Useful Websites, Browsers, Software and Programming.

At DemoGeek.com you'll find step-by-step explanation of the technical issues explained in detail with screenshots and screencasts. Read More...

Contact |  FUG |  Disclaimer

Creative Commons License

Canonical URL by SEO No Duplicate WordPress Plugin