Live is streaming live. Watch now.

Oracle DB Driver

There are two different version of the Oracle DB driver for .NET (ODP.NET) the unmanaged driver and the managed driver.

The one that seems to be more commonly used is the unmanaged ODP.NET driver which requires a full installer to be run on each Windows cell to install and configure all the unmanaged components, registry settings, and the TNS names. Obviously anything that requires an installer is not cloud native as it requires a PCF operator to be involved and the creation of a BOSH addon to install it.

The managed ODP.NET driver is fully managed and can be nuget installed from without any installer or help from a PCF operator. No additional Oracle Client software is required to be installed to connect to an Oracle Database. The managed driver, being cloud friendly, is the one you want to use with your PCF apps whenever possible.

The managed ODP.NET driver is a complete subset of the unmanaged driver’s APIs, so migrating from the unmanaged driver to the managed driver is usually straight forward. It’s a good idea to review the Differences between the ODP.NET Managed Driver and the Unmanaged Driver doc from Oracle.

Migrating to the Managed Driver

Swapping out the unmanaged driver for the managed driver is usually as easy as changing an assembly reference and updating a couple of namespaces.

  1. Remove the existing unmanaged ODP.NET assembly references.
  2. Install the managed ODP.NET nuget package: Install-Package Oracle.ManagedDataAccess
  3. Change the namespace references to the managed driver. Oracle.DataAccess -> Oracle.ManagedDataAccess.
  4. Configure your connection strings using something besides TNS names (see next section)

Managed Driver Configuration

While the most common way to configure the unmanaged driver is to use the TNS names file, this isn’t a remotely 12 factor compliant solution so we’ll need to use something else.

The managed driver supports a variety of way to configure the connection. During initial replatforming it’s often best to directly set the connection information directly in the web.config or the app.config, for example:

<?xml version="1.0"?>
    <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess" />
    <version number="*">
      <dataSource alias="" descriptor="(DESCRIPTION=( ADDRESS_LIST =(ADDRESS= (PROTOCOL=TCP)( (PROTOCOL=TCP)( = (TYPE=SELECT) (METHOD=BASIC) (RETRIES = 180)(DELAY = 5))))"/>

This allows you to quickly configure the ODP.NET managed driver and push your application to PCF without needing to make any code changes. While this is quick and dirty, it’s not 12-factor compliant since the web.config should generally be treated as an immutable artifact.

The better way to configure the connection is to write some custom code that will read the configuration settings from CUPS and directly provide those when opening an Oracle connection.

This should be generalized into a reusable Cloud Foundry connector library.