Friday, August 19, 2016

ADO.NET: Reading CSV Files with ADO.NET fails for .NET 4.0 using Solution Platforms x64 or Any CPU

My development machine runs 64-bit Windows 10. The current application I was adding features to is C#, .NET 4.0 configured to build with Solution Platform, Any CPU. This means that on a 64-bit machine (like my development machine) the code will run as a 64-bit executable. On a 32-bit machine the code will run as a 32-bit executable. The feature I added was the ability to read a CSV file from disk and manipulate the data using a DataTable. This is the same functionality presented in "ADO.NET: Reading CSV Files."

The code (show below) generates an exception at the line connection.Open(). The message associated with the exception is:
The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.

The code which demonstrates this error but of more importance is the version of .NET the application is built with (.NET 4.0) and the Solution Platform (Any CPU). It should be noted that a Solution Platform of x64 would also generate the same exception:

There is no real solution to this issue is there is no 64-bit version of the driver for .NET 4.0 Obviously changing the platform solution to x86 will permit the code to run. That is not a solution. It is a work around. Also upgrading the code to run with 4.5 or later would fix the issue but the only reason this is an issue is that there a requirement to develop a 64-bit application using .NET 4.0.

Changing the version of .NET for the project  can be addressed using Project Properties, the Applications tab:

Changing the platform target for the project to x86 can be addressed using Project Properties, the Build tab:

The code for this application (which obviously generates an exception) can be found on Github at, The solution is named ADODotNetReadingCSVFiles and the project is named CVSToDataTableUsingADODotNet4.0.

No comments :

Post a Comment