Sun
ONE Active Server Pages Product Home Page Developer Site Version
 

ContentsPreviousNextIndex



Creating Database Connections (ASP Server)


Sun ONE Active Server Pages enables you to 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 ONE ASP Server to connect to the database. Then the 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 information, see Configuring a Database.

Sun ONE ASP provides a built-in ADO (ActiveX Data Object) 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 (Open Database Connectivity) drivers are called, and provides "containers" for storing the 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 detailed information about ADO, see ADO Component Reference.

For UNIX and Linux versions of Sun ONE ASP, the setup program automatically installs ODBC drivers for a number of different databases (ODBC drivers are not installed with Sun ONE ASP for Windows). The list of installed drivers can be viewed from the Sun ONE ASP Administration Console, as described in Viewing the List of ODBC Drivers. For Windows systems, the list of installed ODBC drivers can be viewed from the Windows Control Panel. See Microsoft documentation for more information.

Sun ONE ASP includes DataDirect SequeLink 5.3, which enables connections to remote computers running Microsoft Access or Microsoft SQL Server 6.5. For more information, see Configuring SequeLink.

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 ONE ASP, Web developers can specify the connection information for the database by using system DSNs (data source names), file DSNs, or DSN-less connection strings. The appropriate method depends on user preferences, and the environment in which Sun ONE ASP is running. For more information, see Connecting to a Database.

For enterprise applications, it is recommended that ASP developers use system DSNs. The system administrator can use the Sun ONE 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 a shared Web hosting environment, such as with an Internet Service Provider, using system DSNs poses two problems as follows:

Note icon Note It is strongly recommended that you validate your database connection parameters prior to creating a database connection with Sun ONE ASP. An ODBC driver can bring down your ASP Server if incorrect parameters are being passed. You should test your database connections on a nonproduction server.

The following example illustrates the relationship between Sun ONE 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


ContentsPreviousNextIndex