CreateConnection

Description

Creates a new database connection.

Applies to

PSServerClass object

Syntax

ASP targets

psServer.CreateConnection( connectionstring, user, password )

JSP targets ( syntax with user name and password )

psServer.CreateConnection ( pageContext, Driver, URL, user, password, 
{bTrace} )

JSP targets ( syntax with database properties )

psServer.CreateConnection ( pageContext, Driver, URL, Properties, 
{bTrace} )

Argument

Description

connectionstring

A string that specifies connection parameters (for example, the name of the data source to which you want to connect).

user

The user name for the connection.

password

The password for the specified user name.

pageContext

The implicit pageContext object available to JSP targets.

Driver

The connection mechanism used to connect to the database.

URL

The location of the database to which you want to connect. The database URL is obtained from the database JDBC driver documentation.

Properties

Any properties that your JDBC driver uses to connect to the database. If properties are defined, you must also define the user ID and password in the properties that you list.

bTrace (Optional)

Allows tracing if set to true. The default is false.

Returns

PSConnectionClass object

Usage

CreateConnection defines a set of reusable parameters for connecting to a database.

At runtime, CreateConnection has the following behavior:

Application server

Runtime behavior

ASP

Creates an ADODB.Connection object

JSP

Creates a JDBC connection object

Examples

Example 1

The following example creates a new connection for an ASP target and stores the object reference in the myconnect variable. The connection specifies “SalesDB” as the data source. The user ID is “DBA” and the password is “SQL”:

myconnect = psServer.CreateConnection("DSN=SalesDB", "DBA", "SQL");

Example 2

The following example creates a new connection for a JSP target and turns on tracing:

PSConnectionClass myConnect;
myConnect = psServer.CreateConnection(pageContext, 
	"com.sybase.jdbc2.jdbc.SybDriver",
	"jdbc:sybase:Tds:localhost:2638", "dba", "sql",
	true);