Tuesday, November 1, 2011

How Uninstalling The .NET Framework Can Screw Up ODP.NET

Recently I started working on my first project that uses Oracle as the backend database.  Since Microsoft has deprecated the Oracle client built into the .NET framework, I am using ODP.NET from Oracle.  This client works well and follows the familiar patterns familiar to ADO.NET developers, i.e. Connections, Command objects, DataReaders, etc.

However, during development of the project I ran into a gotcha.  I saw some other blog posts describing this same fix and resolution, but I figured one more on explanation on the internet couldn't hurt, right?  More search results for the same problem :)

In the .NET Framework's machine.config file, DBProviderFactories for custom providers (i.e. non System.Data.Odbc, System.Data.OleDb, and System.Data.SqlClient providers) are listed in a <DBProviderFactories> element so the .NET Framework can instantiate connections them when you reference the provider in the provider attribute of the connection string.  In the case of the Oracle ODP.NET client, the entry looks like this:

My gotcha happened when I uninstalled the .NET Framework to try and fix some sort of unrelated corruption issue.  At the time I was unaware of this provider factory entry, so I was confused as to why ODP.NET would not work after I re-installed the framework.  I could not create a connection.  After a while, google finally told me that it is because the DBProviderFactory entry above was missing, since I re-installed the .NET framework and a fresh copy of the machine.config file was put on my machine. 

A quick re-install of ODP.NET fixed everything.  Fail on my part, I guess.


No comments:

Post a Comment