3

How can I use the 32bit MS access driver for odbc connection in python 64bit? Can it be done by altering the environment handle or odbc constants in pypyodbc, or creating a bit conversion file?
Another thought (not sure if possible): Is there a way to switch to a 32bit python.exe during code-execution (JUST for when a user wants to pull access database)? Essentially something like...

if access api called and struct.calcsize("P") == 8: open python 32bit interpreter and connect to 32bit driver

Open to all solutions...Thanks

asdf
  • 836
  • 1
  • 12
  • 29

1 Answers1

5

Articles, forums, and SO Posts are abound on this topic.

Succinctly put, you cannot connect (at application level) a 64-bit Python.exe to a 32-bit MS Access ODBC driver (odbcad32.exe) since simply data is stored and processed differently between the types. However with backwards compatibility, it is advised to work in lowest common denominator as a 64-bit OS can run 32-bit applications and same level programs can "talk" to each other.

As for a dynamic setting to switch modes, this may be a very extensive workaround as the 32-bit python.exe and 64-bit python.exe are essentially distinct installed applications with packages like pypyodbc corresponding to each other. So above installing both versions, you would need to script with either:

  1. one python version that exits itself and calls other version using platform or variable length calculation as you mention with: struct.calcsize("p");
  2. at command line (e.g., shell script, batch file);
  3. via external program (e.g., Excel/Access VBA, Java, C#, php.exe);

External applications will need to select which version will run the python script based on installed ODBC driver, looking at registry key as indicator, or variable type size. This may also require creating path variables to both python.exe versions and be assured they do not conflict with each other, selecting one as default.

Many choose to deploy two versions of application depending on users' CPU environment.

Community
  • 1
  • 1
Parfait
  • 104,375
  • 17
  • 94
  • 125
  • Thanks, can we discuss how to go about approach 1? I've tested the odbc connection via 32bit python and it works. Now the plan is switching between the two elegantly during mid execution – asdf Jun 08 '15 at 15:52
  • Created a new question regarding 1. http://stackoverflow.com/questions/30716663/switching-from-64bit-python-exe-to-32bit-in-mid-execution – asdf Jun 08 '15 at 18:41