Product Documentation

SQL Reference Guide

Previous Topic

Next Topic

CONNECT

Description

Establishes a connection to a database. Optionally, the CONNECT statement can also specify a name for the connection and a user-name/password for authentication.

Syntax

CONNECT TO connect_string

[AS connection_name]

[USER user_name]

[USING password]

connect_string::

{ DEFAULT

| db_name

| port@host_name:db_name }

Arguments

Arguments to CONNECT must either be string literals enclosed in quotation marks or character-string host variables.

connect_string

The string that specifies the database to connect to. If the CONNECT statement specifies DEFAULT, FairCom DB SQL tries to connect to the environment-defined database, if any. (How you define the default database varies between operating systems. On Unix, the value of the DB_NAME environment variable specifies the default connect string.)

The connect string can be a simple database name or a complete connect string. A complete connect string has the following components:

port

The port number, default 6597

host_name

Name or IP address of the system where the database resides.

db_name

Name of the database.

connection_name

The name for the connection for use in DISCONNECT and SET CONNECTION statements. If the CONNECT statement omits a connection name, the default is the name of the database. Connection names must be unique.

user_name

User name for authentication of the connection. FairCom DB SQL verifies the user name against a corresponding password before it connects to the database. If omitted, the default value depends on the environment. (On UNIX, the value of the DH_USER environment variable specifies the default user name. If DH_USER is not set, the value of the USER environment variable specifies the default user name.)

password

Password for authentication of the connection. FairCom DB SQL verifies the password against a corresponding user name before it connects to the database. If omitted, the default value depends on the environment.

(On Unix, the value of the DH_PASSWD environment variable specifies the default password.)

Notes

  • Arguments to CONNECT must either be string literals enclosed in quotation marks or character-string host variables.
  • An application can connect to more than one database at a time, with a maximum of 10 connections. However, the application can actually gain access to only one database at a time. The database name specified in the CONNECT statement becomes the active one.
  • If an application executes an FairCom DB SQL statement before connecting to a database, FairCom DB SQLtries to connect to the database specified through the DB_NAME environment variable, if that environment variable is defined. If the connection is successful, the FairCom DB SQL statement executes on that database.

Authorization

None.

Examples

The following examples illustrate the CONNECT statement:

  • The first statement shown connects to the “salesdb” database on the local system.
  • The second statement connects to the “custdb” database on the local system using a network protocol.
  • The third statement connects to the “custdb” database on the local mode, using the local pipe IPC protocol.
  • The fourth statement connects to the environment-defined database by default (if any).

CONNECT TO 'salesdb' AS 'sales_conn';

CONNECT TO '6597@localhost:custdb' AS 'cust_conn';

CONNECT TO '6597@testbox:custdb' AS 'cust_conn';

CONNECT TO DEFAULT;

SQL Compliance

SQL-92

Environment

Embedded SQL and interactive

Related Statements

DISCONNECT, SET CONNECTION

TOCIndex