CONNECT statement 

A CONNECT statement opens a database session and a transaction for a database user.

Syntax

<connect_statement> ::=
  CONNECT <parameter_name> IDENTIFIED BY <parameter_name> [<connect_option>...]
| CONNECT <parameter_name> IDENTIFIED BY <password> [<connect_option>...]
| CONNECT <user_name> IDENTIFIED BY <parameter_name> [<connect_option>...]
| CONNECT <user_name> IDENTIFIED BY <parameter_name> [<connect_option>...]

<connect_option> ::=
  SQLMODE <INTERNAL | ANSI | DB2 | ORACLE>
| ISOLATION LEVEL <unsigned_integer> | TIMEOUT <unsigned_integer>
| TERMCHAR SET <termchar_set_name>

parameter_name, password, user_name, unsigned_integer, termchar_set_name

Explanation

If the parameter name/user name and parameter name/password combination is valid, the user opens a database session and gains access to the database. As a result, he or she is the current user in this session.

A transaction is opened implicitly (see transactions). The COMMIT statement or ROLLBACK statement ends a transaction and opens a new one implicitly. At the end of each transaction, all locks assigned to the transaction are released, providing they are not maintained by a KEEP LOCK. The isolation specification in the connect statement is applied to each new transaction.

Each connect option may only be specified once.

SQL mode

The specification SQLMODE <INTERNAL | ANSI | DB2 | ORACLE> can be used to select the SQL mode. The default SQL mode is INTERNAL.

The CONNECT option SQLMODE <INTERNAL | ANSI | DB2 | ORACLE> is not allowed in programs. The appropriate precompiler option must be used to specify an SQLMODE other than INTERNAL.

Locks / ISOLATION LEVEL

The unsigned integer after ISOLATION LEVEL keywords may only have the values 0, 1, 2, 3, 10, 15, 20, and 30.

Locks (see transactions) can be requested either implicitly or explicitly. Explicit lock requests are made with the LOCK statement. The specified isolation level determines whether a lock is requested implicitly or explicitly. The length of time for which an implicit SHARE lock is maintained also depends on the isolation level. Exclusive locks set implicitly cannot be released within a transaction. Explicit lock requests are possible with every isolation level.

The selected isolation level affects both the degree of concurrency and the guaranteed consistency. A high degree of concurrency is characterized by a state in which a maximum number of concurrent transactions can process a database without long waiting periods for locks to be released. As far as consistency is concerned, various phenomena can arise through concurrent access to the same database:

The following table indicates the phenomena that can occur with each isolation level:

 

The lower the value of the isolation level, the higher the degree of concurrency and the lower the guaranteed consistency. This means that a compromise between concurrency and consistency that best suits the requirements of the application at hand must always be found.

TIMEOUT

The TIMEOUT value defines the maximum period of inactivity during a database session. The inactivity period is the time interval between the completion of an SQL statement and the next SQL statement. The session is terminated with a ROLLBACK WORK RELEASE when the specified maximum inactivity period is exceeded.

TIMEOUT values are specified in seconds. The specified TIMEOUT value must be less than or equal to the defined maximum TIMEOUT value.

If no TIMEOUT value is specified, the database uses the maximum TIMEOUT value or the SESSION_TIMEOUT value, depending on which is smaller. The SESSION_TIMEOUT value is determined when the database system is installed.

If the TIMEOUT value is set to 0, the inactivity period is not monitored. This can result in a situation where database resources are not available again even though the associated application was concluded or aborted without a RELEASE statement.

Users with the NOT EXCLUSIVE attribute

Users defined with the attribute NOT EXCLUSIVE can open several sessions at the same time. Whenever this is the case, or whenever two users of the same usergroup open a session at the same time, the sessions are considered to be distinct. This means that lock requests of the sessions concerned can collide.

TERMCHAR SET

Terminal character set name

User Manual: SAP DB ® Definition of Terms ® Language Support (Termchar Sets