2
votes

I have a very simple application on .Net that connect to Oracle using ODP (was compiled with Oracle.DataAccess dll 10.2). I want to check "connection prerequisite" (application will be able to connect to DB) before installing this aplication on other computers?

How can I check that ODP.NET version 10.2 or higher is installed on target host (registry check is not enopugh)?

I know that I can check ODP entries in registry - but this will not check Oracle Client and compatibility between client and ODP. Also, if ODP was installed by ODAC XCopy installation - registry may be not updated by new ODP entry. And - if I am installing on the computer, DB was installed on, Oracle Client can be not installed separately.

And one more issue: When I tried to run "test connection" method from installation, that use referenced dll on machine, that has only ODAC (with ODP) 11, - "Oracle.DataAccess.Client.OracleException The provider is not compatible with the version of Oracle client at Oracle.DataAccess.Client.OracleInit.Initialize() at Oracle.DataAccess.Client.OracleConnection..cctor()" error message was thrown (policies for both ODAC 10.2 and 11 are exists in GAC (assembly), pointing to Oracle.DataAccess 11 from ODP 2x bin).

So, How and which components can I check to ensure appropriate versions of ODP and Oracle Client were installed and application will be connected?

Thank you in advance!

1

1 Answers

0
votes

You can use the DataProvider Factory Classes from .Net. This will show all data providers that are available to your current .Net installation / process. I have a blog post here on how to do it. I put it in place to prevent our users from using versions of Oracle that were not supported with .Net 4.0.

http://blog.tsells.com/2011/05/12/oracle-11g-release-2-and-net-framework-4-0-and-version-checking/

I recently found out that Oracle is not supporting the .net 4.0 framework with any version of the Oracle Provider for .Net prior to 11.2.0.2. (See Oracle Data Provider for .NET (ODP) Supported Configurations [ID 726240.1] from oracle support for more details).

Since the prior versions work (10.2, 11.1, 11.2.0.1) then I needed a way to prevent end users from using the wrong version. I searched the net and could not find any one who was able to do this so I did some digging. After some testing I came up with the following code.

 System.Data.Common.DbProviderFactory factory =
                    System.Data.Common.DbProviderFactories.GetFactory("Oracle.DataAccess.Client");

                if (factory == null)
                    return false;

                Type t = factory.GetType();

                int majorversion = t.Assembly.GetName().Version.Major;

                // Do not allow any major versions less than 4
                if (majorversion < 4)
                    return false;

This code will use the same data provider that is registered with the .net framework version you are using. This ensures you are not out of sink in your environment and allows you to inspect the version of the dll installed. For this example – I am just checking that ODP is 4.0 or higher (first release of odp for .net 4).