Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,
I have a problem and i need your support,

I am currently working on a msaccess database management software using c#.net,
I added a pasword the msaccess file, however when i try to open the file using C#.NET, it gives and error "not a valid password"

What I have tried:

my code is as follows
C#
        public OleDbConnection Connection = new OleDbConnection("Provider= Microsoft.Jet.OleDb.4.0;" +
            "Data Source =" + Application.StartupPath + "\\Database.mdb;" +
            "Jet OLEDB:Database Password=123456");

OleDbCommand command = new OleDbCommand("SELECT * FROM MyTable", Connection);

Thanks in advance,
Posted
Updated 12-Apr-22 14:19pm
v2
Comments
Dave Kreskowiak 12-Apr-22 13:56pm    
If you used the "Set Database Password" menu item in Access to set the password, it's telling you the password you're giving in the connection string is wrong. It's that simple.

1 solution

Try
C#
public OleDbConnection Connection = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Application.StartupPath + "\\Database.mdb;" + "Jet OLEDB:Database Password=123456;");
Note the semi-colon inside the quotation marks.

If that doesn't work then make sure your password is less than 14 characters as that can have an impact.

If that doesn't work, make sure you are using the correct driver - try
C#
public OleDbConnection Connection = new OleDbConnection("Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "\\Database.mdb;" + "Jet OLEDB:Database Password=123456;");
You might also want to consider upgrading your Access database(s) to .accdb as .mdb is slated for retirement
 
Share this answer
 
Comments
z3ngew 12-Apr-22 14:31pm    
Thank you for your support, the problem was in the password itself

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