Thread: Access DB 2007

  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Rep Power

    Access DB 2007

    Dear all,
    I am facing some problems while accessing the AccessDB 2007 from pythonwin. Could you please help. Or also if you know any other way using win32com to access the access2007 db.

    ActivePython (ActiveState Software Inc.) based on
    Python 2.7.2 (default, Jun 24 2011, 12:22:14) [MSC v.1500 64 bit (AMD64)] on win32

    Operating System: Windows 7

    import sys
    from win32com.client import Dispatch
    except ImportError as e:
    print e

    if __name__ == '__main__':
    data_source = "C:\\temp\\Database1.accdb"
    access = Dispatch('ADODB.Connection')
    access.Open('PROVIDER=Microsoft.ACE.OLEDB.12.0;Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\\temp\\Database1.accdb;')


    Traceback (most recent call last):
    File "D:\Data\Python Scripts\For the heck of sharepoint\", line 11, in <module>
    access.Open('PROVIDER=Microsoft.ACE.OLEDB.12.0;Driver={Microsoft Access Driver (*.mdb, *.accdb)}
    File "<COMObject ADODB.Connection>", line 3, in Open
    File "C:\ActivePython27\lib\site-packages\win32com\client\", line 276, in _ApplyTypes_
    result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
    pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'ADODB.Connection', u'Provider canno
    t be found. It may not be properly installed.', u'C:\\Windows\\HELP\\ADO270.CHM', 1240655, -21468245
    82), None)
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Rep Power

    64bit v 32bit

    I believe you are running a 64bit OS and an 64bit build of Python. However the Access 2007 drivers you are using are 32bit (it wasn't until 2010 that they produced a 64bit version).

    I happen to have both 32bit and 64bit Python builds installed for testing; the Access database opens fine with the given commands on the 32bit version but not the 64bit.

    I've not (yet) been able to work out a solution if you need to use the 64bit build but there is a Microsoft Access Database Engine 2010 Redistributable that has a 64bit version you could try.
    Last edited by Quackajack; September 13th, 2012 at 12:44 AM. Reason: Added link
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Rep Power
    I left it to Python to work out the reading and updating for me, so the following works with the versions I have and are currently sufficient to get around my work.

    Code Snippet:
    access = Dispatch('Access.Application')
    dbpath = 'myDB.accdb'
    print dbpath
    dbengine = access.DBEngine
    workspace = dbengine.Workspaces(0)
    newdb = workspace.OpenDatabase(dbpath)
    recordSet = newdb.Recordset('select * from Table1')

    while not recordSet.EOF:
    print recordSet.Fields('ID').Value

    Thanks !

IMN logo majestic logo threadwatch logo seochat tools logo