home > features > access

Microsoft Access and DSNs

Customers using Windows Server to host websites have a special folder for Microsoft Access database files.

The data folder

Your home folder contais a special folder named data. This folder is used to store Microsoft Access database files, and any other data files which your website needs to modify. Any files placed in the data folder automatically inherit write permissions for the web server.

It is recommended that data files be placed in this folder, and not in a folder within your website. This protects them from being directly accessible by web browsers, which could potentially lead to disclosure of sensitive information.

Connecting to an Access database

When using Microsoft Access database files to store data, you have the option to use DSN connections or DSN-less connections. A DSN, or "data source name", contains information about how to connect to a database, including the database name, and any authentication information. A DSN-less connection does not use a DSN, but rather includes the information that would be contained in a DSN in the script code.

DSN-less connections

Microsoft has deprecated the ODBC provider on which DSN connections rely, so developers are strongly encouraged by Microsoft to use native OLE DB providers in "DSN-less" connections.

A DSN-less connection includes information about your Access database file in the script code. You can alternatively store the information in a text file in your account, but outside the HTML document root, and include the file within your ASP code. This effectively creates your own local DSN.

A DSN-less connection means there is no limit to the number of databases you can store in your data folder. You can also name your database files anything you like. The following example shows how to connect using ASP.

'Specify absolute path to database file
DataFile = "D:\users\E\example\data\guestbook.mdb"

'Make connection string
ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & DataFile

'Create Command object, connect to database
Set MyCommand = Server.CreateObject("ADODB.Command")
MyCommand.ActiveConnection = ConnectionString

If you are an ASP.NET developer, you can also store connection strings in your application's web.config file.
<configuration>
  <!-- application specific settings -->
  <appSettings>
      <add key="ConnectionString" value="your connection string" />
  </appSettings>

  <system.web>
     ...
  </system.web>
</configuration>

DSN connections

A DSN, or "data source name", contains information about how to connect to a database, including the database name, and any authentication information. To use a DSN in your ASP scripts, use code similar to the following.
ConnectionString = "FileDSN=example01.dsn"

Set MyCommand = Server.CreateObject("ADODB.Command")
MyCommand.ActiveConnection = ConnectionString

Replace "example01.dsn" with the DSN name.

Creating DSNs

DSNs are created in your account using AMS Control Panel. Read Data access for complete steps.