30

I've got a 32 bit .net 2.0 app that uses the Jet OLEDB 4.0.

It runs fin on Windows 8 32 bit, but not on the 64 bit. on 64 bit I'm getting an error:

'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine. at System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionString constr, DataSourceWrapper& datasrcWrapper)

I am aware that you can't use that database (driver) with a 64 bit EXE. However I've not read anything about it not working with the 32 bit exe.

What I tried:

  1. Installed the MS Access Database Engine 2010 32 bit (and restarted)
  2. Verified that msjet40.dll is in the "C:\Windows\SysWOW64\msjet40.dll" directory and registered it with RegSvr32.

So I think (hope) that if I can install the database support it'll just work.

Problem is, I can't find any place to download it.

Clay Nichols
  • 11,848
  • 30
  • 109
  • 170
  • Not available. Change your EXE project's Platform target setting to x86 so the 32-bit version will work. – Hans Passant Dec 11 '12 at 00:04
  • @Hans, my .net app is already compiled as a 32 bit app (confirmed b/c it runs on a 32 bit version of Windows). Is that different from targeting x86? – Clay Nichols Dec 11 '12 at 17:51
  • 1
    The default target for .NET 2 apps on VS2005 and VS2008 is AnyCPU. Which will make it run as a 64-bit process on the 64-bit version of Windows. So don't assume anything and check your Platform target setting, x86 is required. – Hans Passant Dec 11 '12 at 17:56
  • If that's the case then wouldn't the 64 bit driver have done the trick for us? (Just wondering. your tip is worth a try either way) – Clay Nichols Dec 12 '12 at 21:01

2 Answers2

26

On modern Windows this driver isn't available by default anymore, but you can download as Microsoft Access Database Engine 2010 Redistributable on the MS site. If your app is 32 bits be sure to download and install the 32 bits variant because to my knowledge the 32 and 64 bit variant cannot coexist.

Depending on how your app locates its db driver, that might be all that's needed. However, if you use an UDL file there's one extra step - you need to edit that file. Unfortunately, on a 64bits machine the wizard used to edit UDL files is 64 bits by default, it won't see the JET driver and just slap whatever driver it finds first in the UDL file. There are 2 ways to solve this issue:

  1. start the 32 bits UDL wizard like this: C:\Windows\syswow64\rundll32.exe "C:\Program Files (x86)\Common Files\System\Ole DB\oledb32.dll",OpenDSLFile C:\path\to\your.udl. Note that I could use this technique on a Win7 64 Pro, but it didn't work on a Server 2008R2 (could be my mistake, just mentioning)
  2. open the UDL file in Notepad or another text editor, it should more or less have this format:

[oledb] ; Everything after this line is an OLE DB initstring Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Path\To\The\database.mdb;Persist Security Info=False

That should allow your app to start correctly.

fvu
  • 32,488
  • 6
  • 61
  • 79
  • I don't have a .udl file. I see how to create a blank .udl file. Do I create that in the app directory? Do I give i the .dll? HOw does the app or Jet OLEDB know to "look" for it there? – Clay Nichols Dec 11 '12 at 15:26
  • @ClayNichols not all applications use an UDL file, it's just an extra layer of indirection that allows more flexibility in the configuration of the applications. Maybe your application doesn't need one, the path to the database file could be stored inside the app, or configured by the app in some other way. Did you install the driver I mentioned in the mean time? Because, once you've done that the error should either go away, or change, eg to signal that it can't locate the mdb file. – fvu Dec 11 '12 at 17:31
  • Yes, I installed that driver. Oh, sorry, yes, I'd already tried that earlier (forgot to note that). Tried both the 32 bit version (and then uninstalled it) and then the 64 bit version. Same error both times. I assume that a 32 bit app needs the 32 bit version, right? – Clay Nichols Dec 11 '12 at 17:45
  • Yes it does, and as both drivers cannot coexist you indeed have to deinstall the 64 bits driver before installing the 32 bit driver. It's not logical that the driver appears to be missing even after you installed the 32 bit driver. Can you try to run the command I mentioned in point 1, in the initial screen you can see all registered drivers, in this case for 32 bits. – fvu Dec 11 '12 at 21:36
  • fvu, to clarify: I installed the MS Acess DB engine 2010. Do you mean the the command to start the UDL wizard? – Clay Nichols Dec 12 '12 at 15:58
  • @ClayNichols no, it's not logical that your app doesn't pick up the driver after it was properly installed - the manual registration wth regsvr32 isn't necessary afaik. You could start the 32 bits udl wizard to see whether that one sees the driver, as a kind of extra check. But this is beginning to look like something that might be Win8 related. – fvu Dec 12 '12 at 23:26
  • This is the download of the [Microsoft Access Database Engine 2016 Redistributable](https://www.microsoft.com/en-us/download/details.aspx?id=54920). Both 32 bit and 64 bit can be downloaded. – Uwe Keim Apr 28 '23 at 15:59
3

Make sure to target x86 on your project in Visual Studio. This should fix your trouble.

Kyle Blake
  • 39
  • 1