By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,991 Members | 1,888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,991 IT Pros & Developers. It's quick & easy.

How to get connected to *.mdb with pypyodbc py2.7 win64

P: 4
I'm working on a script that make consults on mdb files with the module pypyodbc, but when it's time to connect with the file it give me an exception.

Python 2.7.9 (default, Dec 10 2014, 12:28:03) [MSC v.1500 64 bit (AMD64)] on win32

This is the code:

Expand|Select|Wrap|Line Numbers
  1. def make_consult(fpath, table, column_name, searched_val):
  2. #    Try No. 1
  3.     con = pypyodbc.win_connect_mdb(fpath)
  4. #    Try No. 2
  5. #    connection_string = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=%s" %fpath
  6. #    con = pypyodbc.connect(connection_string)
  7.     cur = con.cursor()
  8.     sql = ("""SELECT * FROM """ + table + """ WHERE """ + column_name + """ LIKE '%""" + searched_val + """'%;""")
  9.     rsql = cur.execute(sql)
  10.     rsql = rsql.fetchall()
  11.     cur.close()
  12.     con.close()
  13.     return rsql
  14.  

In both tries I get the same exception:

Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "<stdin>", line 1, in <module>
  3.   File "C:\Python27\64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 682, in runfile
  4.     execfile(filename, namespace)
  5.   File "C:\Python27\64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
  6.     exec(compile(scripttext, filename, 'exec'), glob, loc)
  7.   File "C:/AAA/Extractor de Datos.py", line 46, in <module>
  8.     a = make_consult(p, table_name(p), 'ClaveInst', 'RbRomanza1')
  9.   File "C:/AAA/Extractor de Datos.py", line 35, in make_consult
  10.     con = pypyodbc.connect(connection_string)
  11.   File "build\bdist.win-amd64\egg\pypyodbc.py", line 2434, in __init__
  12.   File "build\bdist.win-amd64\egg\pypyodbc.py", line 2483, in connect
  13.   File "build\bdist.win-amd64\egg\pypyodbc.py", line 988, in check_success
  14.   File "build\bdist.win-amd64\egg\pypyodbc.py", line 964, in ctrl_err
  15. pypyodbc.Error: (u'HY000', u"[HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x10dc Thread 0x5d0 DBC 0x4338008                                                              Jet'.")
  16.  
May 7 '15 #1
Share this Question
Share on Google+
1 Reply


P: 4
After a while of looking for how can fix this i think i got it...

On Windows 8.1 64-bits, Python 64-bits, MS Office 32-bits

1. Install AccessDatabaseEngine (because MS Office 32 bits)
https://www.microsoft.com/en-us/down....aspx?id=13255

2. Verify this: Control Panel/Administrative Tools ->
right click on ODBC Data Sources (32-bits) in Target:
%windir%\syswow64\odbcad32.exe
right click on ODBC Data Sources (64-bits) in Target:
%windir%\system32\odbcad32.exe

3. Uninstall Python 64-bits and install Python 32-bits and pypyodbc module

Done...
By the way, in the code above line 8:
(the second '% must be %')
Expand|Select|Wrap|Line Numbers
  1.     sql = ("""SELECT * FROM """ + table + """ WHERE """ + column_name + """ LIKE '%""" + searched_val + """'%;""")
  2.  
Replace by this
Expand|Select|Wrap|Line Numbers
  1.     sql = ("""SELECT * FROM %s WHERE %s LIKE %s;""" %(table, column_name, "'%" + searched_val + "%'"))
  2.  
Hope this help somebody else...
May 7 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.