On Feb 11, 10:43 am, Ken McDonald <kmmcdon...@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