Chapter 3 DynaScript Predefined Objects


connection properties

The connection object has these properties:

autoCommit property

Syntax

connection.autoCommit

Description

If true, each SQL statement executed using the connection is automatically committed immediately after it is executed.

Note  

chained mode
Open Client connections are automatically set to CHAINED = ON which is equal to autoCommit=false. Use autoCommit property to set chained mode to off (autoCommit=true).

Example

This example adds $1000 to account 999999999. The insert is executed and committed immediately:

<!--SCRIPT
connection.autoCommit = true;
query = connection.CreateQuery( "insert into savings values ( '999999999', '1000' )" );
-->

connected property

Syntax

connection.connected 

Attributes

This property is read-only.

Description

Uses a Boolean value to indicate whether a connection has been made to the database.

Example

This example displays the return. True indicates a successful connection, false indicates no connection has been made.

<!--SCRIPT 
document.writeln( connection.connected );
connection.Connect();
document.writeln( connection.connected );
connection.Disconnect();
document.writeln( connection.connected );
-->

This example has an output of:

false
true
false

See also

The "Disconnect method"

The "Connect method"

connectionType property

Syntax

connection.connectionType

Attributes

This property is read-only.

Description

The type of connection (string). One of:

Example

This example displays the connection type for a script's default connection object:

<!--SCRIPT 
// This script displays the type of connection
// being used.
document.Write( "This is an " );
document.Write( connection.connectionType );
document.WriteLn( " connection." );
-->

connectParameters property

Syntax

connection.connectParameters

Description

Connection parameters for an ODBC data source (string).

Example

This example lists the connection parameters for the ODBC data source:

<!--SCRIPT 
document.WriteLn( connection.connectParameters );
-->

This example could have the following output:

autostop = no

database property

Syntax

connection.database

Description

The name of the database to which an Open Client connection (string) is made.

Example

This example changes the database to which "myConnection" will connect.

<!--SCRIPT 
myConn = site.GetConnection ( "myConnection" );
myConn.database = "newDatabaseName";
-->

databaseType property

Syntax

connection.databaseType 

Attributes

This property is read-only.

Description

The type of database to which you are connecting; for example, Adaptive Server Enterprise.

Example

This example displays the type of database that is currently connected to:

<!--SCRIPT
document.WriteLn( connection.databaseType );
-->

dataSource property

Syntax

connection.dataSource 

Description

Name of an ODBC data source (string).

Example

This example changes the data sourcethat "MyConnection" uses to connect to "PowerDynamo Demo":

<!--SCRIPT 
myConn = site.GetConnection ( "MyConnection" );
myConn.datasource = "PowerDynamo Demo";
-->

dataSourceList property

Syntax

connection.dataSourceList 

Attributes

This property is read-only.

Description

Names of all available ODBC data sources (array of strings).

Example

This example lists all the available ODBC data sources:

<!--SCRIPT 
list = connection.dataSourceList;
i = 0;
while( exists( list[i] ) ) {
document.writeln( list[i] );
i++;
}
-->

This example might have the following output:

SQL Anywhere Sample
PowerDynamo Demo

description property

Syntax

connection.description

Description

Description associated with the connection (string).

Example

This example displays the description associated with the connection:

<!--SCRIPT 
document.WriteLn( connection.description );
-->

If the connection includes a description, this example might have output similar to:

Connection to the sample site.

isolationLevel property

Syntax

connection.isolationLevel

Description

The isolation level for the database that you are connected to. You must be connected to set the isolation level. You can set this value with an integer or a string but it is always retrieved as a string. The possible values are:

If you set the isolation level to a value that the database does not recognize, the old isolation value will remain.

Example

This example displays the current isolation level and then resets the isolation level to 3:

<!--SCRIPT 
myConn=site.GetConnection("MyConnection")
myConn.Connect();
document.WriteLn( "The isolation level = " + myConn.isolationLevel )
myConn.isolationLevel = 3;
document.WriteLn( "The isolation level = " + myConn.isolationLevel )
-->

name property

Syntax

connection.name 

Description

Name of the connection object (string). The name of the default connection is <default> .

Example

This example displays the name of the connection object. The Connections folder in Sybase Central lists all connection object names.

<!--SCRIPT 
/* display the name of a connection object */
document.WriteLn( connection.name );
-->

This example has an output of:

<default>

password property

Syntax

connection.password 

Description

User password for the data source (string).

Example

This example changes the password for "MyConnection" to "secret":

<!--SCRIPT 
myConn = site.GetConnection ( "MyConnection" );
myconn.password = "secret";
-->

server property

Syntax

connection.server 

Description

Server name for the Open Client connection (string). This property can be used only when you are using an Open Client connection.

Example

This example displays the server name to which the connection object is connected:

<!--SCRIPT 
/* display the server name */
document.WriteLn( connection.server );
-->

This example has an output of:

myserver

simulateCursors property

Syntax

connection.simulateCursors

Description

Allows support for movement through a query result set for individual connections. This property is useful when working with Adaptive Server Enterprise connections.

Note  

[Adaptive Server Enterprise]
The cursor support of Adaptive Server Enterprise is not as extensive as that of Adaptive Server Anywhere, and some of the Move functions are unavailable.

To use Move , MoveFirst , MoveLast , MovePrevious or MoveRelative with an Adaptive Server Enterprise connection you simulate the cursor abilities of Adaptive Server Anywhere using connection.simulateCursors.

To simulate cursors for all connections indefinitely, modify your Registry as follows:

From your system's Registry Editor, open the following file: HKEY_LOCAL_MACHINE\SOFTWARE\SYBASE\SYBASE TOOLS

Add the new string value name Simulate Cursors with the string value of "yes."

Using simulated cursors may cause a decline in performance. When possible, use MoveNext instead.

Example

This example allows MovePrevious to be used with an Adaptive Server Enterprise connection:

<!--SQL 
select lname from customer
-->
<!--script
connection.simulateCursors = true;
SQL.MoveLast()
while( SQL.MovePrevious() ) {
document.writeln( SQL.GetValue(1) );
}
-->

See also

"query object"

The "query properties"

The "Move method"

The "MoveFirst method"

The "MoveLast method"

The "MoveNext method "

The "MovePrevious method"

The "MoveRelative method"

userId property

Syntax

connection.userId 

Description

User name for the ODBC data source (string).

Example

This example gets the connection "Temp" and changes the password and user ID.

<!--SCRIPT 
// change the password and userId of the "Temp"
// connection object
myConn=site.GetConnection ( "Temp" );
myConn.password = "Top";
myConn.userId = "Secret";
-->

 


Copyright © 1999 Sybase, Inc. All rights reserved.