Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi all

in my csharp application i want to set connection string for password protected access database ...

i create access databse with this way :

open database with Exclusive and set password ...

now i create connection string like below :

public static string strconnection = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}\FDA_DB.mdb", Application.StartupPath.ToString())+";Jet OLEDB:Database Password=12345;";


but it not work ...

please help me

thanks a lot
Posted
Comments
[no name] 17-May-13 14:08pm    
"but it not work" is not at all helpful or describe any kind of a problem.

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 ("Microsoft Access Database File"), 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
[no name] 17-May-13 14:59pm    
i do this but only create this :
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\FDA\Project_FDA\Project_FDA\bin\Debug\FDA_DB.mdb

and dont show any password information ...
How about something more like:

test
public static string strconnection = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}\FDA_DB.mdb", Application.StartupPath.ToString())+";Jet OLEDB:Database Password=12345;";;


public static string strconnection = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}\FDA_DB.mdb;Jet OLEDB:Database Password=12345;", Application.StartupPath.ToString());


And do you need the ToString?

And should you be using JET? Or ACE? What error do you get?
 
Share this answer
 
v2
Comments
[no name] 17-May-13 15:02pm    
when use syntax 2 of your post get this error : Not a valid password.
PIEBALDconsult 17-May-13 15:07pm    
You may need to provide an ID and password. I use:

System.String.Format
(
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Jet OLEDB:Database Password={1};User ID={2};Password={3}"
,
System.Environment.ExpandEnvironmentVariables ( FileName )
,
Password
,
UserName
,
UserPass
)


and default to ID admin with an empty password.
[no name] 17-May-13 15:10pm    
i write this but not work again :

public static string strconnection = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}\FDA_DB.mdb;Jet OLEDB:Database Password=eepersian.ir;User ID=admin;", Application.StartupPath.ToString());
PIEBALDconsult 17-May-13 15:18pm    
also add the empty password.
[no name] 17-May-13 15:30pm    
when password empty get this error :

---------------------------
Microsoft Visual Studio
---------------------------
Entering break mode failed for the following reason: Source file 'E:\FDA\Project_FDA\Project_FDA\Class_Methods.cs' does not belong to the project being debugged.



Usually, this condition occurs when the project was not rebuilt prior to starting the debugging session, when the assembly file for the project is out of date, or when the project source files were moved to a different disk location between the time the project was built and the debugging session was started.



Edit and Continue will be disabled for this debugging session.
---------------------------
OK
---------------------------

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