access to MS Access password-protected database?

Kenneth McDonald kenneth.m.mcdonald at sbcglobal.net
Wed Feb 11 15:24:40 EST 2009


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 <kmmcdon... at medicine.wisc.edu>
> 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




More information about the Python-list mailing list