I need to list a server's geodatabases, to analyze and process them. My users are however creating both personal geodatabases and MS Access geodatabases.

Listing mdb files reports both types of databases, I woudl like to narrow the list down to geodatabases only. The boolean workspace property is_geodatabase would be exactly what I need to use, as it indicates whether a database is spatially enabled or not. Unfortunately, this property is only available for SDE databases.

I am using ArcGIS 10.0. and the script below. The choice was made to list mdb files by extension using os.walk() rather than arcpy.ListWorkspaces() for speed of process, and because ListWorkspaces retrieves MS Access databases anyway. How can I amend my script to report only personal geodatabases, and not flat MS acess databases?

for path, subdirs, files in os.walk(analyzed_root_folder):          
    for x in files:        
        if x.lower().endswith(".mdb") == True:
            ext_mdb.append( os.path.join(path, x))

1 Answer 1


Check it with odbc and search if database contain table starting with GDB_

enter image description here

import pyodbc

db_file = "C:/path/to/my/database/MyDataBase.mdb"
user = ''
password = ''
odbc_conn_str = 'DRIVER={Microsoft Access Driver (*.mdb)};DBQ=%s;UID=%s;PWD=%s' % \
                (db_file, user, password)
cnxn = pyodbc.connect(odbc_conn_str)
cursor = cnxn.cursor()
if cursor.tables(table='GDB_GeomColums').fetchone():
   print('This is ArcGIS Personal Geodatabase')

del cursor 
  • do you know if a particular encoding is required for the connexion string? and/or how I can find this out? My dbfile variable is in iso-8859-1, as it is in French and I have to accomodate accentuated characters. I am getting encoding errors, even after deocoding db_file into unicode or recoding it into utf-8, or into the default codepage reported by my cmd window. Thanks!
    – Hélène
    Dec 1, 2015 at 8:36
  • 1
    you can change your console for work in output encoding or pass values by argv in client encoding to script. the script read your client encoding (forced by a param or auto detected) and your fonction can reencode your value to utf-8. if you speak french as me there is a good article by sam&max encoding-en-python-une-bonne-fois-pour-toute Dec 1, 2015 at 9:14

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.