Database connections on 64-bit systems

Hello everyone,

If you’re running a x64 variant of Windows, you might bump into the following problem whilst developing programs that work with databases:

You can’t seem to establish a connection to the database.

This usually means that there aren’ t 64-bit drivers available for the database engine you’re using (For example, MS Access)

The solution for your problem is easy:

  • If you are developing a .NET application in Visual Studio:
    • For Visual Basic projects, go to the Compile tab and press the Advanced Compile Options button.
      In the dialog change the Target CPU to x86
    • For Visual C# projects, go to the Build tab and change Platform Target to x86
  • If you are developing a Java application and you’re using DSN:
    • Add a System DSN using the odbcad32.exe located in C:\Windows\SysWOW64\odbcad32.exe and NOT the one located in C:\Windows\System32\odbcad32.exe (The one that opens when you go to Control Panel > Administrative Tools > Data Sources (ODBC))

For some database engines (such as SQL Server) there are 64-bit drivers available (and usually automaticly installed).
Therefor you can develop 64-bit applications for SQL Server, but most other database engines only work with 32-bit drivers.

That’s pretty much the basic solution to the problem.

If you have any questions, please ask them and I’ll do my best to help you 🙂

– Dirk

P.S.: Incase you’re wondering how you have to work with DSN files in .NET, here is a small code snippet to establish a connection using a System DSN with ODBC:

Dim oCon As New System.Data.Odbc.OdbcConnection("DSN=myDSN")

3 thoughts on “Database connections on 64-bit systems”

  1. I don’t really consider Access as a Database. It’s a desktop product, and you need MS drivers installed if you want to distribute it with your application.

    I would suggest SQL Server Compact, which is file based (no need for an instance like with the full SQL Server).

    And it works on 32 and 64 bit (if you install the proper drivers).

    1. IF you install the correct drivers then yes, you can use SQL CE in a 64-bit application.
      By default, those drivers aren’t installed and for those who wish to avoid the hassle of searching for / downloading of the proper drivers, they can easily change the build options 😉

Leave a Reply

Your email address will not be published.

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.