Tag Archives: oracle

System.Data.OracleClient and Windows 7… love at first sight!


I spent nearly two days trying to resolve this issue. My new desktop at work is running Windows 7 (64-bit) and some of our applications are still using System.Data.OracleClient as an adapter instead of Oracle’s own ODP.NET. Microsoft’s driver interops with Oracle’s own client installed on the developer machine (oci.dll). We need to continue running our web applications under 32-bit IIS, which is where the problem lies.

FYI… According to Microsoft:

The types in System.Data.OracleClient are deprecated. The types are supported in version 4 of the .NET Framework but will be removed in a future release. Microsoft recommends that you use a third-party Oracle provider.

Back to the comment about IIS. Apparently, IIS 7 in Windows 7 is 64-bit only. Yes, you can set an application pool to 32-bit. That would be perfectly fine, except that Oracle’s client native methods don’t like running through WoW64. So, you have to install both the 64-bit client and the 32-bit client. After all, 32-bit adapter code can’t call a 64-bit client. If you fire up procmon, though, you’ll see that calling the 32-bit Oracle client still queries 64-bit settings (and fails if they don’t exist). WoW64!, indeed.

Continue reading to see my resolution…
Note: this forces Oracle to use 32-bit only in a 64-bit environment.
Continue reading System.Data.OracleClient and Windows 7… love at first sight!

Flattr this!

Oracle Exception: Could not load file or assembly ‘Oracle.DataAccess, Version=…

Last week, I was having performance issues with my workstation. I was told to remove unused files and applications. I had previously installed ODAC 11g for the Oracle Data Providers. After realizing they were not backwards compatible with the Oracle10g providers we’re using in production, I removed ODAC 11g using the Oracle Universal Installer. Apparently, that doesn’t completely remove references to the 11g client or components.

After removing files and directories, I began receiving the following error when accessing an application locally:

    Exception message: Could not load file or assembly 'Oracle.DataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) 

To see what Oracle libraries are installed in the GAC, I ran the following command from a Visual Studio command prompt:

gacutil /l | find /i "Oracle" > c:\Scripts\oracle.txt

This gave me the following list (note: Oracle libraries are installed by ODAC 11g)

Oracle.DataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86
  Oracle.Management.Omo, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86
  Oracle.VsDevTools, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86
  Oracle.Web, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86
  Policy.2.102.Oracle.DataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86
  System.Data.OracleClient, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86
  Oracle.DataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342
  Oracle.DataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342
  Oracle.Management.Omo, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342
  Oracle.VsDevTools, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342
  Policy.1.102.Oracle.DataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342
  Policy.10.1.Oracle.DataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342
  Policy.10.2.Oracle.DataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342
  Policy.9.2.Oracle.DataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342
  System.Data.OracleClient, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

I have spent a week trying to figure out why these libraries wouldn’t uninstall from the GAC and why I couldn’t possibly remove them from the Oracle Universal Installer.

To manually uninstall these libraries, you’ll have to run the following commands from a Visual Studio Command Prompt:

gacutil /u "Oracle.Management.Omo, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86"
gacutil /u "Oracle.VsDevTools, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86"
gacutil /u "Oracle.Web, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86"
gacutil /u "Policy.2.102.Oracle.DataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86"

Here’s the part that got me: I installed ODT, not just ODAC. This comes with a number of add-ons for Visual Studio (including Health Monitoring and Profiling). So, you have to manually edit the machine.config to get everything completely removed.
Edit C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config and remove all references from the above libraries.

After following these steps, I was finally able to load the application locally using the ODAC/ODP.NET libraries for Oracle 10g.

Flattr this!

Fluent NHibernate error: Unable to cast object of type ‘Oracle.DataAccess.Client.OracleConnection’ to type ‘System.Data.Common.DbConnection’.

After developing an application in Fluent NHibernate, I’ve received the following Error and Stack Trace:

Unable to cast object of type 'Oracle.DataAccess.Client.OracleConnection' to type 'System.Data.Common.DbConnection'. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidCastException: Unable to cast object of type 'Oracle.DataAccess.Client.OracleConnection' to type 'System.Data.Common.DbConnection'.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 

[InvalidCastException: Unable to cast object of type 'Oracle.DataAccess.Client.OracleConnection' to type 'System.Data.Common.DbConnection'.]
   NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Prepare() +43
   NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper) +65
   NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory) +80
   NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) +598
   NHibernate.Cfg.Configuration.BuildSessionFactory() +87
   FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +49

[FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

   FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +69
   ETeacherWeb.DataAccess.DataSession.get_SessionFactory() +641
   ETeacherWeb.HttpModules.NHibernateSessionModule.<Init>b__0(Object , EventArgs ) +8
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

The server is running Oracle 9.2 client, without ODP.NET. In order to fix this, I copied version 9.2 libraries to the server.

The libraries required were:
Oracle.DataAccess.dll (application/bin folder)
OraOps9.dll (oracle/9.2/bin)

The above directories will of course be different for you, but they should help. Also, the Oracle bin folder must be accessible via the %PATH% variable.

If possible, the much easier fix is to install a full Oracle client, including ODP.NET.

Flattr this!