CONNECT

Connects a user ident to a database.

connect.png

 

where database-specifics is:

database_specifics.png

 

Usage

Embedded, Interactive, Module.

Description

The ident is logged into the specified database. The database can exist on the local machine, a local database, or on another machine in a network configuration, a remote database.

The database, connection, ident and the password can be supplied either using a host variable or as a literal value.

If an empty string is specified for database, a connection is established to the DEFAULT database, see the System Management Manual, The Default Database, for details on how the DEFAULT database is defined in the Mimer SQL system.

If ident is not specified (or ident is specified as blank), the name of the current operating system user is assumed. If the (implicitly or explicitly) specified ident has an OS_USER login that matches the current system user name, the connection is established without checking the password. See ALTER IDENT for more details on how to add an OS_USER login for an ident.

Note:It is only possible to establish a connection to a remote database without specifying ident (or specifying a blank ident) if both the node on which the database resides and the node from which the connection is attempted are running the Windows operating system, and the NamedPipes protocol is used for the network communication.
It is not possible for the database server node to determine the name of the operating system user currently using the remote machine in other network configurations.

When connected, the ident is able to access the database and becomes the current ident (i.e. the name the returned by SESSION_USER).

If connection is specified, the name must be a valid identifier or an empty string.

Note:Connection names must be unique. If an empty string is specified, or if no connection name is given, the value of database will be used as the connection name.

Password and connection are case sensitive in the CONNECT statement.

Ident and database are not case sensitive in the CONNECT statement.

See SQL Identifiers for more information.

Restrictions

Only idents of type USER can connect to a database using the CONNECT statement.

Notes

If it is desired that a CONNECT TO DEFAULT be effectively performed, but with the possibility of specifying one or more of connection, ident or password, then specify database-specifics but supply an empty string for database.

The maximum length of database, connection, ident and password is 128 characters.

If an SQL statement is executed in an application without first executing a CONNECT statement, an implicit CONNECT TO DEFAULT is performed.

This requires that a USER ident with an OS_USER login with the same name exist in the default database with the same name as the operating system user, and that the default database either be a local database or a remote database residing on a node which allows the name of the current operating system user to be determined – see the related note in the Description section above for details.

Such an implicit default connection will only be established if the CONNECT statement has not been previously executed in the application. This means that if an explicit connection has been previously established and then disconnected, any subsequent attempt to execute an SQL statement without a current connection will result in either a Connection does not exist error or a transaction rollback depending on the context of the SQL statement.

If only the implicit default connection has been previously established and then disconnected, any subsequent attempt to execute an SQL statement without a current connection will result in that connection being re-established.

Observe that it is possible for the implicit default connection to exist but not be currently active (this will be the case if a connection has been subsequently established and then disconnected).

We recommend that Mimer SQL applications always establish explicit connections and reliance on the implicit default connection is discouraged.

Earlier versions of Mimer SQL used a different syntax for the CONNECT statement, see Deprecated Features. This syntax is still supported for backward compatibility, but its use is not recommended in new applications.

Example

The following example connects the user JOE to proddatabase using the password hopPsan7:

CONNECT TO 'proddatabase' USER 'JOE' USING 'hopPsan7';

Standard Compliance

Standard

Compliance

Comments

SQL-2016

Features outside core

Feature F771, “Connection management”.

 

Mimer SQL extension

The USING password clause is a Mimer SQL extension.