Link to home
Start Free TrialLog in
Avatar of hshliang
hshliang

asked on

How to open a Jet database with OLE DB

I am learning to do OLE DB. I manage to open the CDataSource with the method Open(). But when I try to open an Access database that has a database password, it fails. I look up the Help and found a 'prop' call DBPROP_JETOLEDB_DATABASEPASSWORD which should be the property for the initial string. However, when I compile, this constant is NOT defined.
Q: 1, Is this the way ( to use DBPROPSET) to open a password protected Jet (Access) database?
2, Where do I find the defination of the constant DBPROP_JETOLEDB_DATABASEPASSWORD? it is not mentioned in the help.
Thanks
ASKER CERTIFIED SOLUTION
Avatar of naveenkohli
naveenkohli

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hshliang
hshliang

ASKER

Thank you.
Dear Naveenkohli,
I just find out that CDataSource::Open(Clsid,&propset) only takes one property set and to supply the name of the database, it takes DBPROPSET_DBINIT using DBPROP_INIT_DATASOURCE as property.
How do I add another propertyset (i.e. DBPROPSET_JETOLEDB_DBINIT) with the property of DBPROP_JETOLEDB_DATABASEPASSWORD??

Please help.
Or is there an other way to open the database that is password protected?

I found the answer. In fact the Open function can take an array of CPropertyset with a number of element in the array following it.
See Atldbcli.h , look under CDataSource Open functon
e.g.
CPropertyset ppset[2]
ppset[0].SetGUID(...)
ppset[0].AddProperty(..)...
ppset[1].SetGUID(..)
ppset[1].SetPrperty(..)...

m_datasource.Open(m_clsid, ppset, 2) will work.