
Connecting to a Database using the AccessDataSource Control
The AccessDataSource control connects to the Microsoft Access database file (.mdb file) identified in the DataFile property. You can set the DataFile property to a universal naming convention (UNC) path that points to an Access database file. The following example demonstrates how you can use a root-relative path to identify an Access database that is located in the App_Data folder of the current Web application.
<asp:AccessDataSource
id="AccessDataSource1"
DataFile="~/App_Data/Northwind.mdb"
runat="server"
SelectCommand="SELECT EmployeeID, LastName, FirstName FROM Employees">
</asp:AccessDataSource>
If you are storing an Access database file with your Web application, it is recommended that you store it in the App_Data folder to keep the database private. ASP.NET does not allow files in the App_Data folder to be returned if requested directly. The ASP.NET process identity must be granted read and write file permissions to the Access databases stored in the App_Data folder. For information on the ASP.NET process identity, see Configuring ASP.NET Process Identity.
The AccessDataSource control sets the ProviderName property of the base SqlDataSource class to the System.Data.OleDb provider and connects using the Microsoft.Jet.OLEDB.4.0 OLE DB provider. You cannot set the ProviderName or ConnectionString properties of the AccessDataSource control.
Note: |
|---|
The AccessDataSource will not connect to an Access database that is password-protected; to retrieve data from a password-protected Access database, use the SqlDataSource control.
|