Connecting to a Password-Protected Access Database in ADO
Use the Jet OLEDB:Database Password attribute in the connection string to specify the password.
The sample code contains a single event handler:
Connect 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.
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 +
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( );
}
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.
Subscribe to:
Post Comments (Atom)
Archives
-
▼
2008
(167)
-
▼
September
(75)
- Use a Drag-and-Drop Operation
- Validate an Input Control
- Create an Animated System Tray Icon
- Make a Borderless Form Movable
- Immovable Forms Creation
- Making Multilingual Form in C#
- Using Part of a Main Menu for a Context Menu
- How To Link a Context Menu to a Control
- How to Sort a List View by Any Column
- How to Use an Autocomplete Combo Box
- Restrict a Text Box to Numeric Input
- Force a List Box to Scroll
- Save the Size and Location of a Form
- Find All MDI Child Forms
- Track the Visible Forms in an Application
- Process All the Controls on a Form
- Link Data to a Control in C#
- Add a Control Programmatically in C#
- Perform an XSL Transform
- Generate a Class from a Schema
- Create a Schema for a .NET Class
- Use XML Serialization with Custom Objects
- Validate an XML Document Against a Schema
- Read and Write XML Without Loading an Entire Docum...
- Find Elements with an XPath Search
- Get XML Nodes in a Specific XML Namespace
- Find Specific Elements by Name
- Quickly Append Nodes in an XML Document
- Insert Nodes in an XML Document
- Connecting to a Password-Protected Access Database...
- Connecting to a Microsoft Excel Workbook in ADO
- Connecting to an ODBC Data Source in ADO
- Ensure That Only One Instance of an Application Ca...
- Start a New Process
- Terminate a Process
- Create a Thread-Safe Collection Instance
- Synchronize the Execution of Multiple Threads
- How To Know When a Thread Finishes
- Control the Execution of a Thread
- Execute a Method Using a New Thread
- Execute a Method by Signaling a WaitHandle Object
- Execute a Method Using a Timer
- Execute a Method Asynchronously
- Execute a Method Using the Thread Pool
- Inspect the Attributes of a Program Element Using ...
- Create a Custom Attribute
- Instantiate an Object Using Reflection
- Test an Object's Type
- Retrieve Type Information
- Retrieve Type Information
- Unload Assemblies and Application Domains
- Pass Data Between Application Domains
- Instantiate a Type in a Different Application Domain
- Execute an Assembly in a Different Application Domain
- Load an Assembly into the Current Application Domain
- Create a Type That Can't Cross Application Domain ...
- Creating an Application Domain
- Connecting to an ODBC Data Source
- Avoid Loading Unnecessary Assemblies into Applicat...
- Pass Objects Across Application Domain Boundaries
- Store a Serializable Object to a File
- Create a Strongly Typed Collection
- Copy a Collection to an Array
- Sort an Array or an ArrayList
- Add, Subtract, and Compare Dates and Times
- Creating Dates and Times from Strings
- Use Compiled Regular Expressions
- Validate Input Using Regular Expressions in Csharp
- Encode Binary Data as Text in Csharp
- Convert Basic Value Types to Byte Arrays
- Encode a String Using Alternate Character Encoding
- Prevent People from Decompiling Your Code
- Manage the Global Assembly Cache in Csharp
- Create and Trust a Test Software Publisher Certifi...
- Sign an Assembly with an Authenticode Digital Sign...
-
▼
September
(75)
No comments:
Post a Comment