HOW TO: Connect to a Security-Enhanced Microsoft Access Database by Using Microsoft Visual Studio .NET (823927)
The information in this article applies to:
- Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2003), Professional Edition
- Microsoft Visual Studio .NET (2003), Academic Edition
- Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2002), Professional Edition
- Microsoft Visual Studio .NET (2002), Academic Edition
SUMMARYThis step-by-step article describes how to connect to a
Microsoft Access database by using Microsoft Visual Studio .NET in the following
scenarios:
- Connecting to the database without security
enabled.
- Connecting to the password-protected database.
- Connecting to the database with user-level
security.
back to the
topRequirementsThe following list outlines the recommended hardware,
software, network infrastructure, and service packs that you need: - Microsoft Visual Studio .NET
- Northwind sample database in Microsoft Access
This article assumes that you are familiar with the
following topic: back to the
topConnect to the Access Database Without Security Enabled You can connect to the Access database by using Microsoft JET 4.0 OLE DB Provider. To establish a connection to the Access database that does not have the security option enabled, follow these steps:
- Start Microsoft Visual Studio .NET.
- On the View menu, click Server
Explorer.
- In Server Explorer, right-click Data
Connections, and then click Add
Connection.
- In the Data Link Properties dialog box,
click the Provider tab. In the OLE DB
Provider(s) list, click Microsoft Jet 4.0 OLE DB
Provider, and then click Next.
- On the Connection tab, click
the ellipsis button (...).
- In the Select Access Database dialog box,
locate the Northwind.mdb file in the following folder:
%Program Files%\Microsoft Office\Office10\Samples Note If you are using Microsoft Office Access 2003, the Samples folder is located in the Office11 folder. If you are using Microsoft Office Access 2002, the Samples folder is located in the Office10 folder. - Click Northwind.mdb, and then
click Open.
- In the Data Link Properties dialog box,
click Test Connection. If the connection succeeds, click
OK in the Data Link Properties dialog
box.
back to the
topSet a Password to the Access DatabaseYou can help to protect to your database in Access by adding a password to the database. When you use a password for the database, you give the password before you open the database. Access stores
the database password in an unencrypted form. To set the password for
the Northwind sample database, follow these steps:
- Start Access.
- On the File menu, click
Open.
- In the Open dialog box, locate the Northwind.mdb file in the following folder:
%Program Files%\Microsoft Office\Office10\Samples - Click Northwind.mdb, and then click Open
Exclusive in the Open list.
- In the Microsoft Access dialog box, click
Enable Macros.
- On the Tools menu, point to
Security, and then click Set Database
Password.
- In the Set Database Password dialog box,
type the password in the Password text box. Type the same
password in the Verify text box, and then click
OK.
- Close the Northwind sample database, and then quit Access.
back to the
topConnect to the Password-Protected Access Database You can use Microsoft Jet 4.0 OLE DB Provider to connect to the Access database. To connect to the database,
specify the password in the JET OLB DB: Database Password property. If you do not specify the database password, the
connection fails and you receive the following error message: Unable to connect to database To establish a connection to the Northwind sample database with password protection, follow these steps:
- Start Microsoft Visual Studio .NET.
- On the View menu, click Server
Explorer.
- In Server Explorer, right-click Data
Connections, and then click Add
Connection.
- In the Data Link Properties dialog box,
click the Provider tab. In the OLE DB
Provider(s) list, click Microsoft Jet 4.0 OLE DB
Provider, and then click Next.
- On the Connection tab, click
the ellipsis button (...).
- In the Select Access Database dialog box,
locate the Northwind.mdb file in the following folder:
%Program Files%\Microsoft Office\Office10\Samples - Click Northwind.mdb, and then
click Open.
- In the Data Link Properties dialog box,
click the All tab.
- Click Jet OLEDB:Database Password, and then click Edit Value.
- In the Edit Property Value dialog box,
type the password that you set for the database in the Property
Value text box, and then click OK.
- In the Data Link Properties dialog box,
click OK.
back to the
topUnset the Database Password You can remove the database password from the sample
database Northwind.mdb. To do this, follow these steps:
- Start Microsoft Access.
- On the File menu, click
Open.
- In the Open dialog box, find the Northwind.mdb file in the following folder:
%Program Files%\Microsoft Office\Office10\Samples - Click Northwind.mdb, and then click Open
Exclusive in the Open list.
- In the Password Required dialog box, type
the database password, and then click OK.
- In the Microsoft Access dialog box, click
Enable Macros.
- On the Tools menu, point to
Security, and then click Unset Database
Password.
- In the Unset Database Password dialog box,
type the database password, and then click OK.
- Close the Northwind sample database, and then quit Microsoft
Access.
back to the
topCreate User-Level Security for the Access Database User-level security can be provided for the Access
database to help to prevent the entry of unauthorized users to the database. When user-level security is provided for the database, you can also set the security
account password for that particular user account. The security password
helps to prevent an unauthorized user from connecting to the database. By default, Access assigns a blank password for the Admin user account and other new user accounts that you create in your
workgroup. You can create or change your own user account password.
The Access workgroup information file stores the information of
members of the workgroup, including the user passwords. Access reads the
workgroup information file while opening a database to find whether the user
has permissions. Create a workgroup
file (System1.mdw), and then provide user-level security by creating a user account
that is named testuser, and set the password for the user account as testuser. To do this, follow these steps: - Start Microsoft Access.
- On the Tools menu, point to
Security, and then click Workgroup
Administrator.
- In the Workgroup Administrator dialog box,
click Create.
- In the Workgroup Owner Information dialog
box, type System123 in the Name text
box. In the Workgroup ID text box, type
12345, and then click OK.
- In the Workgroup Information File dialog
box, type C:\Access Files\System1.mdw as the path, and then click OK.
- In the Confirm Workgroup Information
dialog box, click OK. Click OK in the You have successfully created the workgroup information file
dialog box.
- In the Workgroup Administrator dialog box,
click Join.
- In the Workgroup Information File dialog
box, click OK. Click OK in the You have successfully joined the workgroup defined by the workgroup
information file dialog box.
- In the Workgroup Administrator dialog box,
click OK.
- On the File menu, click
Open.
- In the Open dialog box, find the
Northwind.mdb file in the following folder:
%Program Files%\Microsoft Office\Office10\Samples - Click Northwind.mdb, and then
click Open.
- In the Microsoft Access dialog box, click
Enable Macros.
- On the Tools menu, point to
Security, and then click User and Group
Accounts.
- In the User and Group Accounts dialog box,
click New on the Users tab.
- In the New User/Group dialog box, type
testuser in the Name text box, and
type 1234 in the Personal ID text box, and
then click OK.
- In the Available Groups list, click
Admins, and then click
Add>>.
- Click the Change Logon Password tab. In
the Old Password text box, type your old password.
- In the New Password and
the Verify text boxes, type the new password
admin, and then click OK.
- Close the Northwind sample database, and then quit Access.
- Start Microsoft Access.
- On the File menu, click
Open.
- In the Open dialog box, find the Northwind.mdb file in the following folder:
%Program Files%\Microsoft Office\Office10\Samples - Select the Northwind.mdb file, and then
click Open.
- In the Logon dialog box, type
testuser in the Name text box, and then click
OK.
- In the Microsoft Access dialog box, click
Enable Macros.
- On the Tools menu, point to
Security, and then click User and Group
Accounts.
- In the User and Group Accounts dialog box,
click the Change Logon Password tab.
- In the New Password and
the Verify text boxes, type testuser, and
then click OK.
- Close the Northwind sample database, and then quit Access.
back to the
topConnect to the User-Level Security-Enabled Access Database You can use Microsoft Jet 4.0 OLE DB Provider to connect to the database. The Jet OLEDB:System database property is set to the path of the workgroup file. User account
name testuser and password testuser are set in the User ID and Password properties. If you do not provide any one of these values,
the connection fails, and you receive an error message. To establish a connection to
the Access Northwind sample database that has user-level security enabled, follow these steps:
- Start Microsoft Visual Studio .NET.
- On the View menu, click Server
Explorer.
- In Server Explorer, right-click Data
Connections, and then click Add
Connection.
- In the Data Link Properties dialog box,
click the Provider tab. In the OLE DB
Provider(s) list, click Microsoft Jet 4.0 OLE DB
Provider, and then click Next.
- On the Connection tab, click
the ellipsis button (...).
- In the Select Access Database dialog box,
find the Northwind.mdb file in the following folder:
%Program Files%\Microsoft Office\Office10\Samples - Click Northwind.mdb, and then
click Open.
- In the Data Link Properties dialog box,
click the All tab.
- Click Jet OLEDB:System database, and then click Edit Value.
- In the Edit Property Value dialog box,
type C:\Access Files\System1.mdw in the Property
Value text box, and then click OK.
- Click User ID, and then
click Edit Value.
- In the Edit Property Value dialog box,
type testuser in the Property Value
text box, and then click OK.
- Click Password, and then
click Edit Value.
- In the Edit Property Value dialog box,
type testuser in the Property Value
text box, and then click OK.
- In the Data Link Properties dialog box,
click OK.
- In the Please Enter MS JET OLE DB Initialization
Information dialog box, type testuser in the
Password text box, and then click
OK.
back to the
topREFERENCES For additional information, click the following article
numbers to view the articles in the Microsoft Knowledge Base: 305542
Understanding the Role of Workgroup Information Files in Access Security
132143 ACC: Overview of How to Help Protect a Microsoft Access Database
192919 HOWTO: Automate a Secured Access Database Using Visual Basic
back to
the top
Modification Type: | Major | Last Reviewed: | 8/28/2003 |
---|
Keywords: | kbJET kbHOWTOmaster kbhowto kbUser kbSecurity kbAuthentication kbDatabase KB823927 kbAudDeveloper |
---|
|
|
©2003 Microsoft Corporation. All rights reserved.
|
|