Search code examples
c#oledbdbase

How do I enumerate installed OleDb providers for current processor architecture?


I've a project that connects to a dBase format database file, that I've always done in the past with a connection string of the form of:

PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=MyData.dbf;Extended Properties=dBASE 5.0

I've had to revisit this recently, and have found that when attempting to create an OleDbConnection with that connection string on x64 machines, that have an x86 install of Office on it, it throws an exception.

A quick hack of a fix shows that forcing the application to target x86 only makes it work, but I was hoping to be able to tidy this up and check in advance whether it would fail to create the connection, so that I could customise my import options to suit the available providers.

Is it possible to enumerate the available data providers for the current processor architecture? (other than relying on catching the exception -- after all, the Framework Design Guidelines suggest that you should only throw in exceptional circumstances, and you have a method to check if something would throw an exception)


Solution

  • You could use the OleDbEnumerator class to find out what providers are available. Not sure what the point would be, you'll just end up showing the user an empty list of choices. There is no 64-bit version of the JET provider available and there's no alternative. You'll still get the call from the user, asking you to change your program. As long as you want to support JET, you'll need to set the build target to x86.