Click here to Skip to main content
15,885,990 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

C++
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
Updated 22-Nov-11 2:08am
v2

Use following connection string
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Jet OLEDB:Database Password=MyDbPassword;
 
Share this answer
 
Comments
Shruthi Krupal 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!
Use http://connectionstrings.com/[^] to get the connection string you need.
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900