September 2003
Intermediate to advanced
624 pages
14h 27m
English
You want to connect to a Microsoft Access database that has a database password.
Use the Jet OLEDB:Database
Password attribute in the connection string to
specify the password.
The sample code contains a single event handler:
Button.Click Creates and opens a connection to a password-secured Microsoft Access
database using the OLE DB .NET data provider. Information about the
database is displayed from the properties of the
OleDbConnection object.
The C# code is shown in Example 1-3.
Example 1-3. File: AccessPasswordForm.cs
// Namespaces, variables, and constants 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 ...Read now
Unlock full access