hey plz help me in connecting ms access from C#

Dani AI

Generated

The thread lacks a few key details (WinForms vs ASP.NET, .mdb vs .accdb, runtime bitness, and any attempted code). was right to ask for the OP's code, and 's linked snippet is a useful starting point. The notes below give a compact, practical C# pattern for a login backed by an Access file, plus the most important deployment and security cautions.

Example connection strings (place the .mdb/.accdb in App_Data for ASP.NET and use |DataDirectory|):

/* .mdb (Jet) */
string conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\MyDB.mdb;User Id=admin;Password=;";

/* .accdb (ACE) */
string conn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\MyDB.accdb;Persist Security Info=False;";

Minimal, safe login flow notes (OleDb uses positional parameters ?; parameter order matters):

using(var cn = new OleDbConnection(conn))
{
  cn.Open();
  using(var cmd = new OleDbCommand("SELECT PasswordHash, Salt FROM Users WHERE Username = ?", cn))
  {
    cmd.Parameters.AddWithValue("?", username);
    using(var rdr = cmd.ExecuteReader())
    {
      if (rdr.Read())
      {
        string storedHash = rdr["PasswordHash"].ToString();
        string salt = rdr["Salt"].ToString();
        if (VerifyPassword(password, storedHash, salt)) { /* authenticated */ }
      }
    }
  }
}

Store only salted, iterated hashes (PBKDF2 / Rfc2898DeriveBytes) — never plaintext passwords. Implement VerifyPassword with the same algorithm and salt.

Important cautions and troubleshooting points:

  • ACE/Jet provider bitness: install the correct Access Database Engine and match IIS/app process bitness (enable 32-bit app pool if using 32-bit provider).
  • File permissions: grant the app pool identity write access to the folder holding the .mdb/.accdb.
  • Concurrency and reliability: Access is fine for small, low-concurrency sites. For production or many simultaneous users, move to SQL Server Express / LocalDB or a hosted RDBMS.
  • Always use parameterized queries to avoid SQL injection and test on the target server (permissions and providers often cause the most runtime errors).

If posts the current code and whether this is ASP.NET or WinForms, targeted adjustments can be provided.

Recommended Answers

All 3 Replies

You need to show effort, and what better way than posting the code that you have tried so far? Read member rules.

hiii bro thank u for helpnig me over here

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.