asp.net.ph

AccessDataSource.DataFile Property

System.Web.UI.WebControls Namespace   AccessDataSource Class


.NET Framework version 2.0

Sets or retrieves the location of the Microsoft Access .mdb file.

Syntax


Inline <asp:accessdatasource datafile = strFilePath ... >
Script AccessDataSource.DataFile [ = strFilePath ]

Property Value


strFilePath The location of the Access .mdb file. Absolute, relative, and virtual paths are supported.

The property is read/write with no default value.

Exceptions


Exception Type Condition
ArgumentException An invalid path was given.

Remarks

The DataFile property is a virtual, absolute, or UNC directory path to the Access .mdb file that the AccessDataSource control represents.

  • Relative paths with both forward and backward slashes are supported. For example, "./test/test/Northwind.mdb" maps to the same path as ".\test\test\Northwind.mdb" and "test/test/Northwind.mdb".

  • UNC paths, such as "\\mymachine\somedatadirectory\Northwind.mdb", are also supported.

  • Although absolute physical paths are supported, it is not recommended as these can complicate deployment particularly when file locations are reorganized.

Configuring Permissions for an Access Database

An important aspect of working with an Access .mdb file is to configure permissions properly.

When a Web application uses an Access database, the application must have Read permission to the .mdb file so that it can access the data. In addition, the application must have Write permission to the folder containing the .mdb file, specially to allow users to update the data.

By default, ASP.NET Web applications run in the context of a local machine account called ASPNET ( for Microsoft Windows 2000 and Microsoft Windows XP) or in the context of the NETWORK SERVICE account ( for Microsoft Windows 2003). For example, for Windows 2000 or Windows XP, if the Web server is named MyServer, ASP.NET applications on the MyServer computer run in the context of the local account MyServer\ASPNET.

Therefore, to use an Access database in an ASP.NET Web application, you must configure the folder containing the Access database to have both Read and Write permissions.

When you create a Web site in the Microsoft Visual Web Developer Web development tool, Visual Web Developer creates a folder named App_Data below the current root folder. The folder is designed to be a store for application data, including Access databases. The App_Data folder is also used by ASP.NET to store databases that the system maintains, such as the database for membership and roles. When Visual Web Developer creates the App_Data folder, it grants Read and Write permissions for the folder to the ASPNET or NETWORK SERVICE user account.

NOTE: As a security measure, Visual Web Developer also configures the App_Data folder so that files in the folder are not served by the Web server. Do not store any Web pages in the App_Data folder, because users will see an error if they request a page from that folder.

Example

The following examples demonstrate how to set the DataFile property.

Dynamically Generated ButtonField ImageButtons
Run Sample | View Source
Using the Built-In Pager with Custom Navigation Controls
Run Sample | View Source
FormView with Default Paging
Run Sample | View Source
See Also

DataSourceMode Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph