7

I'm trying to use pyodbc to access a .mdb on Ubuntu. I've based my progress so far on this link

Query crashes MS Access

I have installed pyodbc, unixodbc, and unixodbc-dev

My code looks like this:

import csv
import pyodbc

MDB = 'URY.mdb'
DRV ='Microsoft Access Driver (*.mdb)'
PWD = 'pass'

conn = pyodbc.connect('DRIVER=%s;DBQ=%s;PWD=%s' % (DRV,MDB,PWD))
curs = conn.cursor()

When I run it, I receive this error message:

Traceback (most recent call last):
  File "mdbscraper.py", line 8, in <module>
    conn = pyodbc.connect('DRIVER=%s;DBQ=%s;PWD=%s' % (DRV,MDB,PWD))
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found,         and no default driver specified (0) (SQLDriverConnect)')

Does anyone have any ideas? Any help would be very much appreciated

Thank you!

4

2 回答 2

5

据我所知,此驱动程序“Microsoft Access Driver (*.mdb)”仅在 Microsoft 主机上可用,因为您使用的是 ubuntu,所以它无法工作。

于 2014-03-18T13:37:37.387 回答
-3
import pyodbc 
DBfile = '/data/MSAccess/Music_Library.mdb'
conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};DBQ='+DBfile)
cursor = conn.cursor()
SQL = 'SELECT Artist, AlbumName FROM RecordCollection ORDER BY Year;'

for row in cursor.execute(SQL): # cursors are iterable
print row.Artist, row.AlbumName

cursor.close()
conn.close()

有The Official Example .. of use ...

于 2012-09-04T15:49:31.627 回答