Access Database that has database password.

How to make connection with Access Database that has database password.

Summary:

This Program will connect to a Microsoft Access database with database password with ADO.net.

Solution

Jet OLEDB:Database Password attribute in the connection string is use to specify the password.

using System;
using System.Configuration;
using System.Text;
using System.Data;
using System.Data.OleDb;
 
 
private void connectButton_Click(object sender, System.EventArgs e)
{
    StringBuilder result = new StringBuilder( );
 
    // Build the connections string incorporating the password.
    String connectionString =
        ConfigurationSettings.AppSettings["MsAccess_Secure_ConnectString"]+
        "Jet OLEDB:Database Password=" + passwordTextBox.Text + ";";
 
    result.Append("ConnectionString: " + Environment.NewLine +
        connectionString + Environment.NewLine + Environment.NewLine);
 
    OleDbConnection conn = new OleDbConnection(connectionString);
    try
    {
        conn.Open( );
 
        // Retrieve some database information.
        result.Append(
            "Connection State: " + conn.State + Environment.NewLine +
            "OLE DB Provider: " + conn.Provider +
            Environment.NewLine +
            "Server Version: " + conn.ServerVersion +
            Environment.NewLine);
 
        conn.Close( );
        result.Append("Connection State: " + conn.State);
    }
    catch(System.Data.OleDb.OleDbException ex)
    {
        conn.Close( );
        result.Append("ERROR: " + ex.Message);
    }
 
    resultTextBox.Text = result.ToString( );
}

Discussion

A Microsoft Access database password requires that users enter a password to obtain access to the database and database objects. This is also known as share-level security. A password does not allow groups or users to have distinct levels of access or permissions. Anyone with the password has unrestricted access to the database.

The Set Database command from the Tools > Security menu is used to set up a database password.

The OLE DB provider for Microsoft Jet has several provider-specific connection string attributes in addition to those defined by ADO.NET. To open a database secured by a Microsoft Access database password, use the Jet OLEDB:Database Password attribute in the connection string to specify the password. This corresponds to the OLE DB property DBPROP_JETOLEDB_DATABASEPASSWORD.

By Kalit Sikka   Popularity  (3052 Views)