Using Oracle from .Net
I’ll bet you’ve always wanted to know: how can I access an Oracle database from .Net in the most easy way possible? With Microsoft .Net Framework, accessing Microsoft databases is easy since the Framework comes with the required drivers (naturally). But since Windows doesn’t come with the drivers for accessing Oracle, and Oracle itself is notoriously terrible in making install packages for their drivers that reliably work on Windows, it is a royal pain to get it to work - sometimes. But now I’ve found the way - read on for the answer.
- Download the Oracle Instant client and extract all the files into the \bin directory of the .Net application with which you want to use it.
- In your application, use the System.Data.OracleClient namespace to access the Oracle database required. Formulate the connection string as follows: “Data Source=server:port/instance; User Id=user; Password=pwd”
Troubleshooting
If you get any errors, make sure that the .Net process identity under which your application/website is running has read access on the bin directory where the Oracle instant client is. Also, if you have a “real” version of Oracle on the computer, and you try to use a TNS name instead of the configuration string example from above, be aware that it will use the TNS file in your official Oracle Home on the computer.