Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C++
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 3:03am
Edited 22-Nov-11 3: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 at 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 at 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 at 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)

Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
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