image\cslogo3d1.gif

Using File DSNs

As discussed in "Creating Connection Strings" in this section, using file DSNs is one way to specify the information needed for establishing a connection to a database from an ASP application. This topic 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 needing to edit 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 you must configure for each database are provided in "Parameters for File DSNs" in this section.

Note about using Windows file DSNs with Chili!Soft ASP for Linux or UNIX

File DSNs and connection strings must be constructed according to the requirements of the ODBC driver being used. On Windows NT, Chili!Soft ASP uses the same ODBC drivers as Microsoft ASP, so you do not need to change any file DSNs or connection strings in order to use them. However, the ODBC drivers available for Linux and UNIX are different than for Windows. In order to connect to a database from an ASP application that you developed for Windows on Chili!Soft ASP for Linux or UNIX, you must edit your file DSNs and connection strings to use the syntax described in this topic.

Also, when porting file DSNs to Linux or UNIX systems, be sure to remove the "control-M" characters that Windows inserts at the end of each line.

The following example shows a file DSN for a Sybase 11 database:

[ODBC]

Driver={Sybase}

Server=Sun

DB=MyDatabase

UID=John

PWD=Some.Password

When finished defining parameters, give the file a DSN filename 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 an ISP, 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 about supported databases

Chili!Soft ASP 3.6 installs the ODBC drivers for a number of databases, but it does not support all databases on all platforms. You can view the list of installed drivers in the Installation Requirements topic for your platform in the "Installing and Uninstalling Chili!Soft ASP" section of "Chapter 2: Installing and Configuring Chili!Soft ASP."

Note about DB2, Microsoft Access, and Microsoft SQL Server databases

- You cannot use DSN-less connection strings or file DSNs for connecting to DB2, Interbase, Microsoft Access, or Microsoft SQL Server 6.5 databases from Chili!Soft ASP for Linux or UNIX; you must use system DSNs.

- With Chili!Soft ASP for Linux or UNIX, before you can reference a Microsoft SQL Server 7.0 database in a DSN-less connection string or a file DSN, your system administrator must take the steps described in "Editing the Microsoft SQL Server Template" in "Chapter 3: Managing Chili!Soft ASP."

See also:

Connecting to a Database in this chapter

Creating Connection Strings in this chapter

Using System DSNs in this chapter

Using FrontPage Database Features in this chapter

Copyright 2001 Sun Microsystems, Inc. All rights reserved. Legal Notice.