f



access to MS Access password-protected database?

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

0
2/11/2009 3:43:22 PM
comp.lang.python 77058 articles. 6 followers. Post Follow

2 Replies
1308 Views

Similar Articles

[PageSpeed] 11

On Feb 11, 10:43=A0am, Ken McDonald <kmmcdon...@medicine.wisc.edu>
wrote:
> Can anyone direct me towards a code snippet showing how to use Python =A0
> to insert data into a password-protected MS Access database? My google =
=A0
> 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=3D90#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 =3D win32com.client.Dispatch('ADODB.connection')

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

cnxtr =3D 'Driver=3D%(driver)s; DBQ=3D%(dbase)s; SYSTEMDB=3D%(sys_mdw)s; UI=
D=3D%
(uid)s; PWD=3D%(pwd)s; ' % parms
cnx.ConnectionString =3D 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 =3D 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.
0
2/11/2009 6:01:37 PM
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...@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

0
2/11/2009 8:24:40 PM
Reply: