access to MS Access password-protected database?

K

Ken McDonald

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
 
I

imageguy

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.
 
K

Kenneth McDonald

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


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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top