0

I am not able to open the access file using python. I am not sure if the problem is with the mdb file or the python commands.

In [1]: import sys, subprocess

In [2]: DATABASE = 'Exam_BackUp.mdb'

In [3]: table_names = subprocess.Popen(["mdb-tables", "-1", DATABASE], stdout=subprocess.PIPE).communicate()[0]
Couldn't open database.

How do I know if the file is microsoft access file? I have checked that mdbtools is installed on my Ubuntu server.

I need to open the (access or fortran) file and save the contents to csv.

1
  • You might be interested in my answer to a similar question here. Commented Nov 6, 2014 at 16:36

2 Answers 2

2

Why not try opening it with an ODBC driver?

A good example is here, reproducing it for your case would be along the lines of:

import pyodbc

DBfile = 'Exam_BackUp.mdb'
conn = pyodbc.connect('FILEDSN='+DBfile)
cursor = conn.cursor()

# Do whatever you want with SQL selects, etc

cursor.close()
conn.close()
Sign up to request clarification or add additional context in comments.

2 Comments

Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')
@shantanuo A quick search here found this solution.
1

You can convert it by the Terminal using mdbtool like this:

Install mdbtools and upgrade it:

pip install mdbtools
pip install --upgrade pip

Then look for the name of the table inside the mdb file:

home/Docs$ mdb-tables 'file.mdb'

And finally convert the file to .csv with this line:

home/Docs$ mdb-export 'file.mdb' 'name_of_table' > 'file.csv'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.