System.InvalidOperationException: 'The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.'
I am getting this error. I don't know how to resolve. My system is 64 bits. I am using Visual Studio 2022 and I have a Microsoft Office 2007 (32bit) installed on my computer. when I searched the Net, it's saying to download Microsoft Access Database Engine 2010 Redistributable. I downloaded the 32-bit version (since my office is 32 bits, not allowing to download 64 bit). but still this error is showing up...
OleDbConnection OledbConn = new OleDbConnection(connString);
//try
//{
OleDbCommand OledbCmd = new OleDbCommand();
OledbCmd.Connection = OledbConn;
OledbConn.Open();
var sheetNames = OledbConn.GetSchema("Tables");
This is part of the code. The error is showing at the line oledbConn.Open();
Note: After installing Microsoft access, only .DLL file is present in the Office 14 folder. The .mdb file and .accdb file was not present. I don't know if this info is relevant.
(1) I installed Microsoft Access build 2010, still not working, (2) I compiled my application in 32-bit and use the 32-bit version of Microsoft.Jet.OLEDB.10.0,still same error
To check if "Microsoft.Jet.OLEDB.4.0" is installed look in the Windows registry. You should find it listed under HKEY_CLASSES_ROOT. Also look for "Microsoft.ACE.OLEDB.12.0" and "Microsoft.ACE.OLEDB.16.0" entries. Then under each of those keys, you should find the corresponding CLSID key which provides a GUID value. For example "HKEY_CLASSES_ROOT\Microsoft.Jet.OLEDB.4.0\CLSID" has REG_SZ value "{dee35070-506b-11cf-b1aa-00aa00b8de95}".
Now "Microsoft.Jet.OLEDB.4.0" is 32-bit only. Microsoft has not provided a 64-bit version. Assuming your using a modern 64-bit operating system, like Windows 10 or Windows 11, you should find entry "HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{dee35070-506b-11cf-b1aa-00aa00b8de95}\InprocServer32" with a REG_SZ value "C:\Windows\SysWOW64\msjetoledb40.dll".
If the above two registry enteries are missing, then "Microsoft.Jet.OLEDB.4.0" is not available.
Now to use "Microsoft.Jet.OLEDB.4.0" from a VB or C# .NET program, executing on a 64-bit OS, the complied executable MUST run as 32-bit. To confirm this, you need the 'corflags.exe' utility from the Windows SDK. You can get the Windows SDK as a seperate download or install it as an option with Visual Studio. I used the version found in "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7 Tools\x64\corflags.exe". Here is an example of what you need to see:
Note, its critical for the '32BITREQ' flag to be set, to force the program to run as 32-bit on a 64-bit OS. If the '32BITREQ' flag is not set, you can force it to be set, by executing "corflags.exe /nologo /32BITREQ+ myprogram.exe". Alternatively, if your using the CSC.EXE compiler, you can specify option "/platform:x86". The default platform value of 'anycpu' is not suitable, as the executable will default to using the 64-bit CLR.
Now if you want to use "Microsoft.ACE.OLEDB.12.0" or "Microsoft.ACE.OLEDB.16.0", these comes in either 32-bit or 64-bit versions, depending which bitness of Office is installed. Alternatively you can download and install the Microsoft Access Database Engine Redistributable. But you can only have either 32-bit or 64-bit engines installed, not both at the same time!
To confirm if you have 32-bit or 64-bit engine version, check for the following registry keys:
If you have the entries under the 'WOW6432Node' node, then you have the 32-bit version. The 'InprocServer32' keys should point to the implementing DLL file, which again should be of the correct bitness.
I have written a simple C# program to check for the various registry keys. The source code is available at this GIST link. Here is some typical output:
I would also recommend you use the SysInternals "Process Monitor" to monitor your program as it executes. This will allow you to confirm exactly which registry keys are being checked.
Ok, I think that covers everything you need to know...