Thursday, July 03, 2014

ODP.NET Managed Data Access (Oracle.ManagedDataAccess.dll) with Enterprise Library

Oracle.ManagedDataAccess.dll is managed Oracle connector that doesn't require any Instant Client to be installed and offers advantage over unmanaged counterparts. It doesn't require any installation on the machine and Oracle.ManagedDataAccess.dll should be placed in execution directory or in probing directory specified in configuration.

Below are the two errors which you may receive while trying to use Oracle Managed Data Access DLL:

1. Activation error occured while trying to get instance of type Database, key ""

Resolution of the dependency failed, type = Microsoft.Practices.EnterpriseLibrary.Data.Database, name = ConnectionString.
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value.-----------------------------------------------
At the time of the exception, the container was: Resolving  Microsoft.Practices.EnterpriseLibrary.Data.Database,ConnectionString (this occurs when wrong provider factory is used or DbProviderFactories hasn't been added to the application configuration or machine.config)

2. Configuration system failed to initialize (this occurs when configuration section doesn't have correct entry)

To make Oracle.ManagedDataAccess.dll work with Enterprise Library few additional obvious configuration changes are required:

 Add configSections section at the top of configuration:
<configSections> <section name="oracleConnectionSettings" type="Microsoft.Practices.EnterpriseLibrary.Data.Oracle.Configuration.OracleConnectionSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" /> <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true"/> <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342" /> </configSections>

Add Db Provider Factories:

In case of ODP.NET to load appropriate factory while creating database machine.config is modified during installation and DbProviderFactories is added however with Oracle.ManagedDataAccess.dll there is no installation required so edit the application configuration file (app.config or web.config) and add following:
<> <DbProviderFactories> <remove invariant="Oracle.ManagedDataAccess" /> <add name="Oracle Managed Data Provider for .NET" invariant="Oracle.ManagedDataAccess" description="Oracle Managed Data Provider for .NET" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342" /> </DbProviderFactories> </>

Make sure to change the version and Public Key Token depending on the version being used.

Connection string for EZConnect looks like:
<connectionStrings> <add name="ConnectionString" connectionString="Data Source=//localhost:1521/Shash;User ID=scott;Password=tiger;" providerName="Oracle.ManagedDataAccess" /> </connectionStrings>

Above configuration changes allow use of Oracle.ManagedDataAccess.dll with Enterprise Library.


  1. Man you saved my day. I was hitting all over the place to have this resolved. At last i saw your post , which resolved the issue.

    1. Glad to hear it worked for you :)