Sun Chili!Soft ASP Sun Chili!Soft
ASP Sun Microsystems

 

Enabling Database Connections on the Server

With Sun Chili!Soft ASP, you can easily display and manipulate information stored in a database from an ASP page. To enable an ASP application to retrieve data from a database, the system administrator must first configure the Sun Chili!Soft ASP Server to connect to the database. Then the Web developer can create and initialize a connection to the database from within the application. This topic provides overview information about enabling a connection on the ASP Server. For more detailed instructions, see "Configuring a Database" in "Chapter 3: Managing Sun Chili!Soft ASP."

Sun Chili!Soft ASP provides built-in ActiveX Data Object (ADO) control that developers can use from within an ASP application to initialize a database connection for retrieving and manipulating data. ADO provides the interface through which ODBC drivers are called and provides "containers" for storing information that is passed to and from the database. The most common container is a Recordset object, which stores the results of a SELECT SQL query. The ADO Connection object establishes connections to databases by using ODBC drivers. For more information about ADO, see "ADO Component Reference" in "Chapter 5: Developer's Reference."

For UNIX and Linux versions of Sun Chili!Soft ASP, the setup program automatically installs ODBC drivers for a number of different databases (Sun Chili!Soft ASP for Windows does not install ODBC drivers). You can view the list of installed drivers from the Administration Console, as described in "Viewing the List of ODBC Drivers" in "Chapter 3: Managing Sun Chili!Soft ASP." For Windows systems, the list of installed ODBC drivers can be viewed from the Windows Control Panel (double-click the Data Sources icon). See Microsoft documentation for more information about using the Windows ODBC Data Source Administrator.

Sun Chili!Soft ASP includes DataDirect SequeLink 4.51a, which enables connections to remote computers running Microsoft Access or Microsoft SQL Server 6.5. For more information, see "Configuring SequeLink" in "Chapter 3: Managing Sun Chili!Soft ASP."

ADO and either the appropriate ODBC driver or SequeLink are required to create a connection to a particular database. ADO uses connection information and the ODBC driver manager to create an instance of the required ODBC driver, which in turn connects to the database.

With Sun Chili!Soft ASP, Web developers can specify the connection information for the database by using system DSNs, file DSNs, or DSN-less connection strings. The appropriate method to use depends on user preferences and the environment in which Sun Chili!Soft ASP is running. For more information, see "Connecting to a Database" in "Chapter 4: Building a Sun Chili!Soft ASP Application."

For enterprise applications, it is recommended that ASP developers use system DSNs. The system administrator can use the Sun Chili!Soft ASP Administration Console to create system DSNs, which can be referenced from within an ASP application for initializing the database connection. For more information about creating a system DSN, see "Configuring Data Source Names (DSNs)" in "Chapter 3: Managing Sun Chili!Soft ASP."

In a shared Web hosting environment, such as with an Internet Service Provider (ISP), using system DSNs poses two problems:

·   A DSN that includes a username and password for the database makes the data source accessible from any ASP page on the server, representing a security risk.

·   Creating DSNs for each customer can be a significant administrative burden for the Web hosting provider. Because Web developers can create them and the database username and password information can be restricted to a specific ASP application, using file DSNs and DSN-less connection strings are more appropriate in a Web hosting environment.

Note

It is strongly recommended that you validate your database connection parameters prior to creating a database connection with Sun Chili!Soft ASP. An ODBC driver can bring down your ASP Server if it is passing incorrect parameters. You should test your database connections on a nonproduction server.

The following example illustrates the relationship between Sun Chili!Soft ASP, ADO, ODBC drivers, and databases.

A connection string on the ASP page specifies the information required by both ADO and the ODBC driver manager for connecting to the database. The following example uses a DSN-less connection string:

connect_string = "Driver={ODBC_driver_name}; Database=[database_name]; UID=[username]; PWD=[password]"

The next line of code creates an instance of the ADO Connection object:

set dbConn = server.createObject ("ADODB.connection")

The following code calls the Open method of the ADO Connection object, which takes the connection_string parameter. In this step, ADO requests that the ODBC driver manager create an instance of the specified ODBC driver. ADO passes the remainder of the connection string to the ODBC driver, which uses this information to connect to the database.

open dbConn connect_string

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