Sun
ONE Active Server Pages Product Home Page Developer Site Version
 

ContentsPreviousNextIndex



Using File DSNs


As discussed in Creating Connection Strings, using file DSNs is one way to specify the information needed for establishing a connection to a database from an ASP application. This section explains how to create a file DSN and reference it from within a connection string.

When you have a number of connection strings referencing the same database, file DSNs can be quicker to implement than DSN-less connection strings. File DSNs can also make ASP applications easier to port from the development environment to the production server because you can edit the database information in a single file, rather than editing multiple connection strings.

To use file DSNs, the first step is to create a file containing the required parameters and values for the database with which you want to connect. Then you simply reference the file from within the connection string, rather than duplicating the database information each time.

To create a file DSN, open a plain text file and specify the parameters for the database to which you want to connect by using the following general syntax:

[ODBC]
a=b
c=d
e=f

where a=b, c=d, and e=f are the key-value pairs that define the database parameters and their values. One of the key-value pairs must specify the name of the ODBC driver for the database. The parameters that must be configured for each database are provided in Parameters for File DSNs.

Note icon Note File DSNs and connection strings must be constructed according to the requirements of the ODBC driver being used. On Windows, Sun ONE Active Server Pages uses the same ODBC drivers as Microsoft ASP, so you do not need to change any file DSNs or connection strings to use them. However, the ODBC drivers available for UNIX and Linux platforms are different than for Windows. To connect to a database from an ASP application that you developed for Windows on Sun ONE ASP for UNIX or Linux, you must edit your file DSNs and connection strings to use the syntax described in this topic.
   Also, when porting file DSNs to UNIX or Linux systems, be sure to remove the "control-M" characters that Windows inserts at the end of each line.

When finished defining parameters, give the file a DSN file name extension (*.dsn) and save it in the document root of your Web server or virtual host.

Once you have created the file DSN, you can refer to it from within a connection string. The syntax to use is as follows:

connect_string = "FileDSN=[MyFileDSN.dsn]"
- or -
connect_string = "File_Name=[MyFileDSN.dsn]"

where [MyFileDSN.dsn] is the absolute path name of the file DSN (*.dsn) containing the database parameters and values.

In a shared Web hosting environment, such as with an Internet Service Provider, you might not know the directory structure above the document root for your virtual host. In this situation, you cannot specify the absolute path name of the file DSN, so you must use the Server.mapPath directive instead. The following example uses a file DSN that is stored in the document root of the virtual host:

dim myConnFile,connection_string
myConnFile = Server.mapPath("/") & "/" & "MyFileDSN.dsn"
connect_string = "FileDSN=" & myConnFile
Note icon Note On UNIX and Linux systems, Sun ONE ASP installs the ODBC drivers to support a number of databases. However, it does not support all databases on all platforms. To see the list of installed drivers for your platform, see Supported in This Release.
   You cannot use DSN-less connection strings or file DSNs for connecting to Microsoft Access or Microsoft SQL Server 6.5 databases from Sun ONE ASP for UNIX or Linux; you must use system DSNs.

In this section:

Parameters for File DSNs

See also:

Connecting to a Database

Creating Connection Strings

Using System DSNs

Using FrontPage Database Features



ContentsPreviousNextIndex