Click here to Skip to main content
15,923,051 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

the below code is Connection String between Access 2010 and C#.net 2010
My Database have password.

C#
Access_Con = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\L_Loan_Database.accdb;Jet OLEDB:Database Password=xxxx;


but I have following error

Can not open database ". It may not be a database that your application recognize, or the file may be corrupted.

I search in the Connectionstrings.com website but don't help me.

tanks a lots.
Posted
Updated 15-Mar-15 2:29am
v2
Comments
Kornfeld Eliyahu Peter 15-Mar-15 8:21am    
Did you set DataDirectory?
bernova 15-Mar-15 8:55am    
???????
bernova 15-Mar-15 9:26am    
How to Set DataDirectory in the class library
bernova 15-Mar-15 8:30am    
No How Do I?

Try setting up a connection in VS with the Server Explorer pane:
1) Open Server Explorer.
2) Right click "Data connections" and select "Add connection"
3) In the dialog that follows, select your DataSource, and database, specify the security info, and press the "Test connection" button.
4) When the connection works, press "OK"
5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file.
 
Share this answer
 
Comments
bernova 15-Mar-15 8:45am    
Tanks OriginalGriff.
because I set password on the access database . shows the same error.
My connection string is wrong.
OriginalGriff 15-Mar-15 8:55am    
SO try what I suggested, and provide the right password! :laugh:
bernova 15-Mar-15 9:25am    
My Question is
are the connection string is correct ?
bernova 15-Mar-15 9:27am    
tanks. but Your solution shows the same error.
OriginalGriff 15-Mar-15 9:42am    
Count to ten, Griff, count to ten...

No, it doesn't - not unless you are failing to connect to your DB when you follow the instructions. Did you press the "Test Connection" button, at all?
You are using |DataDirectory|, which is a placeholder for the actual directory. If not defined otherwise it will be mapped to your application's directory...
If you want the connection engine to look for a different path you should use
C#
AppDomain.CurrentDomain.SetData("DataDirectory", "[your path to the db file]");
 
Share this answer
 
v2
Comments
bernova 15-Mar-15 9:37am    
thanks. I used same above code as following :
AppDomain.CurrentDomain.SetData("DataDirectory", Directory.GetCurrentDirectory());

I Write my Connection String in Class Library (dll). but I can't use above code and shows error

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