-->

x64 Application Accessing mdb database

2020-06-23 08:10发布

问题:

I have an application that needs to be built under x64 platform. I need to access an .mdb file. By accessing I mean, inserting, deleting or updating the db. I having trouble using Jet OLE db and ODBC drivers. With OLE db it shows "Jet Oledb not registered". With ODBC Platform mismatch between driver and application. I can do these operations in X86 platform. But in my application I was asked to build my project under x64 platform. Can anybody provide me with any solution. N.B. I should not use any 3rd application to communicate with x64 app and database.

Thanks to any response in advance.

回答1:

You need to use the newest driver from Microsoft called ACE
Here you can find the download bits

Pay attention to download the correct set (x64 or x86) for your intended target machine Also the connection string should make use of these drivers, so you probably need a connection string like this

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=yourPathToTheMDBFile.mdb;
Persist Security Info=False;

As an alternative you could build your application for x86 platform and, if you don't have any direct interaction with 64bit code, it will works as is in the 64bit operating system. This solution is preferable because you could use the old JET.OleDb.4.0

Let me give a brief explanation of the problem with 64/32bit operating system, Platform used to build applications and 32/64bit drivers:

  • You build your application for AnyCPU platform - Your code works fine in 32/64 bit systems, the code emitted by the JIT compiler will have the same bitness of the guest OS. BUT, you could not use 32bit drivers by 64bit apps and viceversa. JET.OleDB.4.0 is 32bit only. End of game if you compile for AnyCPU and run on 64bit. You need a 64bit driver.
  • You build your application for x86 platform - Your code works fine in 32/64 bit systems, and you can use 32bit drivers. Of course the code emitted by the JIT compiler is 32bit and thus you cannot use 64bit drivers on 64bit systems.