Click here to Skip to main content
13,149,756 members (54,683 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi ,

As i am new to c++ . I am stuck up in connecting to MS Access 2007 Password Protected Database Programmatic-ally .
If i remove the password of my 2007 Access Database , I can fetch all the record in the database . But if i include a password for my MS Access 2007 , i am receiving the error " Cannot open database . It may not be the database that your application recognizes , or the file is corrupted". Please help me in resolving the issue.

Following code is the open method of cdatabase which i am using

LPCTSTR lpszConnect = 
    _T("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ=C:\\a.mdb;Pwd=123");
result = db.Open(NULL,false,false,lpszConnect);

Please help me in resolving the problem .
Posted 22-Nov-11 2:03am
Updated 22-Nov-11 2:08am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use following connection string
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Jet OLEDB:Database Password=MyDbPassword;
Member 7889326 22-Nov-11 8:41am
Thanks a lot for your reply . It is working with the solution provided by you. I just had one more question regarding this , as i am creating a Data Access Layer(i,e separate module) for my whole project. I will be using this Microsoft.ACE.OLEDB method for connecting to Access Database for whole of data handlers . Is this Microsoft.ACE.OLEDB method of connection to database secured and recommendable for all the interactions with database from application.
Maciej Los 19-Feb-13 14:53pm
Good answer. +5!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Use[^] to get the connection string you need.
Maciej Los 19-Feb-13 14:52pm
Short and to the point, +5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170924.2 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100