Oracle – Devart dotConnect For Oracle and Enterprise Library Custom Provider Mappings

devartdotconnectenterprise-libraryoracleprovider

I'm trying to get a simple proof-of-concept working using the trial of Devart's dotConnect for Oracle because we currently use the .Net framework OracleClient (due to be deprecated) but we also have a requirement to connect without the need for the Oracle Client or even the Instant Client. For this reason I am trying to prove to my boss that dotConnect is the tool for the job, given its direct mode and ability to work with Enterprise Library 5 (used in our data access layer). I followed the examples provided by Devart including adding the custom provider map in the app.config in a test app. This all seemed to work on my development machine both in the IDe and as a compiled application, so I wrapped it up in a simple setup and deployment project, built an msi and then installed it on a vanilla Win 7 x86 virtual machine which does not not have the Oracle Client installed to test it out.

It just does not want to work. The test executes a simple select statement and displays the results in a listview (if there are any – you get a message if not). I'm not actually bothered about the results themselves, merely the act of getting them. The problem is when I execute the test I get the ever unhelpful EL error:

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

Here's the offending line of code:

Dim db As Database = EnterpriseLibraryContainer.Current.GetInstance(Of Database)(EnvironmentName)

Here's the provider mapping in the app.config file:

<add databaseType="Devart.Data.Oracle.EnterpriseLibrary.OracleDatabase, Devart.Data.Oracle.EnterpriseLibrary, Version=3.5.4456.40828, Culture=neutral, PublicKeyToken=null" name="Devart.Data.Oracle" />

Here's the connection string from the app.config:

<add name="Testing26_devart" connectionString="User Id=Testing26;Password=Testing26;Server=ORACLE-SERVER;Direct=True;Sid=DEVORA;Port=1523;"
        providerName="Devart.Data.Oracle" />

I know this error can be caused by using the wrong connection string name (amongst other things), but I know this is correct because I retrieve it from the config file in the first place. Also this is exactly the same as the config used in the development environment. The inner exception is this:

Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Data.Database", name = "Testing26_devart".

Exception occurred while: while resolving.

Exception is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value.

I suspect the provider mapping is to blame because if I change the provider in the connection string to System.Data.OracleClient then it has no problem at all finding the connection string but instead complains about the unsupported keyword Direct (from the dotConnect Direct mode switch), which makes sense.

I cannot see what I have done wrong with regards to the provider mapping. I've not used it before but I've used the EL configuration tool to ensure its correct, the custom library is included with the executable (and the other EL libraries). I've looked at several examples, all of which suggest I have the right configuration, so what am, I missing? This is driving me nuts.

Best Answer

It sounds like the DbProviderFactory is not configured. Probably when you install the Devart software it installs the DbProviderFactory in the machine.config. Check the machine.config on your development machine for the DbProviderFactory's existence.

If you don't want to modify machine.config you can add the config information to your app.config. It would look something like:

  <system.data>
    <DbProviderFactories>
      <add name="dotConnect for Oracle" invariant="Devart.Data.Oracle" 
description="Devart dotConnect for Oracle" type="Devart.Data.Oracle.OracleProviderFactory, Devart.Data.Oracle" />        
    </DbProviderFactories>
  </system.data>

I'm not familiar with the Devart libraries so I'm not sure what the Version or PublicKeyToken would be.

If Enterprise Library cannot locate the DbProviderFactory then the database will not be registered and when you try to access the database you will get the message that the object cannot be found in the container.

Related Topic