As discussed in "Creating Connection Strings" in this chapter, 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 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:
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 Sun Chili!Soft ASP for UNIX or Linux
File DSNs and connection strings must be constructed according to the requirements of the ODBC driver being used. On Windows, Sun Chili!Soft ASP 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 Chili!Soft 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.
The following example shows a file DSN for a Sybase 11 database:
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 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:
myConnFile = Server.mapPath("/") & "/" & "MyFileDSN.dsn"
connect_string = "FileDSN=" & myConnFile
Note about supported databases
On UNIX and Linux systems, Sun Chili!Soft 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, go to the platform-specific installation requirements section in "Installing and Uninstalling Sun Chili!Soft ASP" in "Chapter 2: Installing and Configuring Sun Chili!Soft ASP."
Note about Microsoft Access and Microsoft SQL Server databases
You cannot use DSN-less connection strings or file DSNs for connecting to Microsoft Access or Microsoft SQL Server 6.5 databases from Sun Chili!Soft ASP for UNIX or Linux; you must use system DSNs.
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 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.