Reputation: 3488
I'm not really sure why the difference of exceptions on 32-bit and 64-bit running environment. I'm testing next code using Visual Studio 2019 and changing Platform from x86 to x64 and vice versa-
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Public\Documents\my.accdb";
System.Data.Common.DbConnection connection = new System.Data.OleDb.OleDbConnection(connectionString);
try
{
connection.Open();
}
catch (InvalidOperationException e)
{
// occurs when running on 64-bit runtime
}
catch (OleDbException e)
{
// occurs when running on 32-bit runtime
}
Note that I don't have installed Microsoft Access 2013/2016 Runtime. In order to connection to accdb file to succeeded you have to have this installed, but I'm testing if user does not have this installed.
I'm curious why OleDbException does not occur on 64-bit or x64 platform as well?
EDIT
InvalidOperationException message:
The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.
OleDbExceptionMessage:
Unrecognized database format 'C:\Users\Public\Documents\my.accdb'.
Upvotes: 0
Views: 616
Reputation: 23898
I'm curious why OleDbException does not occur on 64-bit or x64 platform as well?
It doesn't occur on 64-bit since 64-bit doesn't have a 'Microsoft.Jet.OLEDB.4.0'
provider.
With 32-bit, the issue looks to be that the driver can't read the accdb
files. With 64-bit, the issue is that the driver doesn't even exist.
INTRODUCTION
The Microsoft OLE DB Provider for Microsoft Jet and the Microsoft Access ODBC driver (Jet ODBC driver) provide an interface to Microsoft Office Access databases. The Microsoft OLE DB Provider for Jet and the Jet ODBC driver are available in 32-bit versions only.
More Information
We do not provide a 64-bit version of the Microsoft OLE DB Provider for Jet. Additionally, we do not provide a 64-bit version of the Jet ODBC driver. If you use the Microsoft OLE DB Provider for Jet or the Jet ODBC driver to connect to a data source in a 64-bit environment, you experience different problems.
For example, you have a 32-bit application that uses the Microsoft OLE DB Provider for Jet. If you migrate the application to run in the 64-bit mode, the application cannot connect to the data source by using the Microsoft OLE DB Provider for Jet. This issue occurs because the application requires a 64-bit version of the Microsoft OLE DB Provider for Jet.
However, we still have the 32-bit version of the Microsoft OLE DB Provider for Jet and the 32-bit version of the Jet ODBC driver. In a 64-bit Windows environment, you can run an application in the 32-bit mode. Therefore, the application can use the 32-bit version of the Microsoft OLE DB Provider for Jet or the 32-bit version of the Jet ODBC driver.
The simplest solution is likely to force x86 (32-bit). Or have your code catch both types of exceptions and deal with them accordingly.
Upvotes: 1