access to MS Access password-protected database?

Discussion in 'Python' started by Ken McDonald, Feb 11, 2009.

  1. Ken McDonald

    Ken McDonald Guest

    Can anyone direct me towards a code snippet showing how to use Python
    to insert data into a password-protected MS Access database? My google
    searches have been uninformative for dbs that are password-protected.

    Thanks,
    Ken
     
    Ken McDonald, Feb 11, 2009
    #1
    1. Advertising

  2. Ken McDonald

    imageguy Guest

    On Feb 11, 10:43 am, Ken McDonald <>
    wrote:
    > Can anyone direct me towards a code snippet showing how to use Python  
    > to insert data into a password-protected MS Access database? My google  
    > searches have been uninformative for dbs that are password-protected.
    >
    > Thanks,
    > Ken


    You post is a little vague on specifics
    - do you actually have access to the db ?
    - can you open it with access ?
    - can you currently read records using python ?

    I am assuming you don't have access to the db through python, once you
    do the rest is straight forward.

    I use DSN-less connections. This link below is quite helpful
    http://www.carlprothman.net/Default.aspx?tabid=90#ODBCDriverForAccess

    If you aren't using the adodbapi (part of the pywin32 package), you
    need to do something like this, assuming you access db is MS-Access
    2000 and above.

    <untested>
    import win32com
    cnx = win32com.client.Dispatch('ADODB.connection')

    parms = {}
    parms['driver'] = '{Microsoft Access Driver (*.mdb)}'
    parms['dbase'] = path_to_mdb
    parms['sys_mdw'] = path_to_workgroup_security
    parms['uid'] = userid_defined_in_mdw
    parhs['pwd'] = pwd_for_uid_in_mdw

    cnxtr = 'Driver=%(driver)s; DBQ=%(dbase)s; SYSTEMDB=%(sys_mdw)s; UID=%
    (uid)s; PWD=%(pwd)s; ' % parms
    cnx.ConnectionString = cnxstr
    cnx.Open()

    </untested>
    once you have an ADO Connection, execute SQL directly on the
    connection like this

    cnx.Execute('INSERT INTO tablename (col1, col2) VALUES ('val1,
    val2);')

    Or alternatively you should create RecordSets and manipulate these.

    IF you need help understanding ADO I would recommend;
    http://www.w3schools.com/ado/default.asp

    The examples are translateable to Python.
    You create recordsets via;
    rs = win32com.client.Dispatch('ADO.RecordSet')


    If you don't have/weren't given the passwords to the DB, but you do
    have access to the workgroup file ('*.MDW') file that stores the uid/
    pwds and permission, then there are several third party tools that
    will recover these for you. Google is your friend.

    If you don't have access to the original .mdw ... well, I can't help
    you and I don't think anyone can.

    Good luck.
     
    imageguy, Feb 11, 2009
    #2
    1. Advertising

  3. Sorry for the vagueness.

    I do have access to the file and can open it using Access. I haven't
    yet done anything involving Python and Access (or Python and Win
    interfacing, for that matter.)

    Thanks,
    Ken


    On Feb 11, 2009, at 12:01 PM, imageguy wrote:

    > On Feb 11, 10:43 am, Ken McDonald <>
    > wrote:
    >> Can anyone direct me towards a code snippet showing how to use Python
    >> to insert data into a password-protected MS Access database? My
    >> google
    >> searches have been uninformative for dbs that are password-protected.
    >>
    >> Thanks,
    >> Ken

    >
    > You post is a little vague on specifics
    > - do you actually have access to the db ?
    > - can you open it with access ?
    > - can you currently read records using python ?
    >
    > I am assuming you don't have access to the db through python, once you
    > do the rest is straight forward.
    >
    > I use DSN-less connections. This link below is quite helpful
    > http://www.carlprothman.net/Default.aspx?tabid=90#ODBCDriverForAccess
    >
    > If you aren't using the adodbapi (part of the pywin32 package), you
    > need to do something like this, assuming you access db is MS-Access
    > 2000 and above.
    >
    > <untested>
    > import win32com
    > cnx = win32com.client.Dispatch('ADODB.connection')
    >
    > parms = {}
    > parms['driver'] = '{Microsoft Access Driver (*.mdb)}'
    > parms['dbase'] = path_to_mdb
    > parms['sys_mdw'] = path_to_workgroup_security
    > parms['uid'] = userid_defined_in_mdw
    > parhs['pwd'] = pwd_for_uid_in_mdw
    >
    > cnxtr = 'Driver=%(driver)s; DBQ=%(dbase)s; SYSTEMDB=%(sys_mdw)s; UID=%
    > (uid)s; PWD=%(pwd)s; ' % parms
    > cnx.ConnectionString = cnxstr
    > cnx.Open()
    >
    > </untested>
    > once you have an ADO Connection, execute SQL directly on the
    > connection like this
    >
    > cnx.Execute('INSERT INTO tablename (col1, col2) VALUES ('val1,
    > val2);')
    >
    > Or alternatively you should create RecordSets and manipulate these.
    >
    > IF you need help understanding ADO I would recommend;
    > http://www.w3schools.com/ado/default.asp
    >
    > The examples are translateable to Python.
    > You create recordsets via;
    > rs = win32com.client.Dispatch('ADO.RecordSet')
    >
    >
    > If you don't have/weren't given the passwords to the DB, but you do
    > have access to the workgroup file ('*.MDW') file that stores the uid/
    > pwds and permission, then there are several third party tools that
    > will recover these for you. Google is your friend.
    >
    > If you don't have access to the original .mdw ... well, I can't help
    > you and I don't think anyone can.
    >
    > Good luck.
    > --
    > http://mail.python.org/mailman/listinfo/python-list
     
    Kenneth McDonald, Feb 11, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    2
    Views:
    562
    Andreas Klemt
    Jul 5, 2003
  2. Paul Lynch
    Replies:
    1
    Views:
    410
    www.MSmobiles.com
    Jul 15, 2004
  3. AAaron123
    Replies:
    2
    Views:
    2,202
    AAaron123
    Jan 16, 2009
  4. AAaron123
    Replies:
    1
    Views:
    1,357
    Oriane
    Jan 16, 2009
  5. Kenneth McDonald
    Replies:
    0
    Views:
    479
    Kenneth McDonald
    Feb 7, 2009
Loading...

Share This Page