2

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.

Steve Pettifer
  • 1,975
  • 1
  • 19
  • 34

1 Answers1

2

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.

Randy Levy
  • 22,566
  • 4
  • 68
  • 94
  • Tuzo you were spot on - the installer for dotConnect adds the entry to the machine.config but doesn't mention this anywhere in the documentation (that I can see), hence why it works perfectly on the development machine. As soon as I added the section to my app.config it burst into life and did exactly as I expected it to. Thank you so much - I spent 2 days trying to work out what was wrong using stuff like fuslogvw, process monitor and more. – Steve Pettifer Apr 12 '12 at 12:31
  • @StevePettifer, it seems you did not pay attention to this article in the product documentation : http://www.devart.com/dotconnect/oracle/docs/Deployment.html. You can find all information you need in it. – Devart Apr 13 '12 at 08:18
  • @Devart - I did read that document but it's not clear that you need this when using the new EL5 methods of getting database instances which (as it turns out) abstracts the DbProviderFactories considerably unless you happen to know that already. Also doesn't say that your installer adds it to machine.config which was the key omission. I'd suggest that you should not add the DbProviderFactories entry in the machine.config during installation and instead make it clear in the documentation that it must be added to app.config/web.config (or, if that's what the user wants, machine.config) manually. – Steve Pettifer Apr 13 '12 at 09:52
  • @StevePettifer - Thank you, your opinion is important for us. We will review our documentation and consider how to improve it. – Devart Apr 13 '12 at 10:40