how do i connect to a password protected database through VB.......

Dani AI

Generated

The answers from show the correct approaches for classic MDB files using DAO or ADO. Additional context that matters years later:

If the file is an ACCDB (Access 2007+) or the app runs on 64-bit Windows, the older Jet provider will not always work. Use the Access Database Engine (ACE) provider or compile your app as 32-bit (x86) when using Jet. Access changed encryption/format at 2007, so a provider mismatch often produces “unrecognized format” or “provider not found” errors.

Quick troubleshooting checklist:

  • Verify the database file path and filesystem permissions (the account running the app must be able to open the file).
  • Check bitness: a 64-bit process cannot load a 32-bit OLE DB provider. Either install the matching ACE provider or run the process as 32-bit.
  • Test the provider outside your app using a .udl file (create a text file, rename to .udl, double-click, configure and Test Connection) to separate provider issues from your code.
  • In VB6 make sure ADODB/DAO references are set; in VB.NET use the appropriate System.Data provider and config files.

Security and operational notes:

  • Avoid hard-coding passwords in source. For .NET, use protected configuration or Windows protected storage; for legacy VB, store secrets outside the code and restrict ACLs.
  • Database-level passwords for Access are not the same as server-based authentication; for multi-user or sensitive data consider migrating to a server DB (SQL Server/Managed service).
  • If the password is lost, recovering the data requires a backup or repair; there is no supported “master reset.”

Finally, if odd characters appear in the connection string (copied from formatted text), replace them with plain ASCII characters — copy/paste corruption is a common source of subtle failures.

Recommended Answers

All 5 Replies

Hi,

If using DAO :
Dim DB As DataBase
Set DB = DBEngine.OpenDatabase("C:\DB1.mdb", False, False, ";PWD=MyPWD")

If using ADO:
Set conn = New ADODB.Connection
conn.ConnectionString = _ "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\DB1.mdb;" & _
"Jet OLEDB:Database " & _ "Password=MyPWD"
conn.Open

Regards
Veena

Hi,

That is:
Set conn = New ADODB.Connection
conn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\DB1.mdb;" & _
"Jet OLEDB:Database Password=MyPwd"
conn.Open

Hi,

I dont know why Icon is being printed.

Jet OLEDB:Database Password

Regards
Veena

Hi,

Replace Icon by ":" (Colon)

thanx a ton veena......m vry grateful 2 u

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.