tags:

views:

119

answers:

1

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)

A: 

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.

Hans Passant
I appreciate for JET there is no x64 driver; but is there an option for any given OleDb connection string?
Rowland Shaw
What do you *really* want to do? Create a connection string builder? Check out the OleDbEnumerator class.
Hans Passant
That looks like it'll do the trick -- I've spent too much time with SqlConnectiosn for my own good..
Rowland Shaw
Oh joy, another not-helpful answer. Have you found the connectionstrings.com website yet?
Hans Passant
I had seen that, I'd also found http://fastdbf.codeplex.com/ which would allow read/write to DBF had that just been the issue at hand
Rowland Shaw