Establishes a connection to a database.
connect [to engine_name] [database database_name] [as connection_name] [user] user_id identified by password engine_name, database_name, connection_name, user_id, password : {identifier | string | hostvar}
connect using connect_string : {identifier | string | hostvar}
is the name of the engine to which you are connecting.
is the name of the database to which you are connecting. It must conform to the rules for identifiers and cannot be a variable.
you can optionally name a connection by specifying the as clause. This allows multiple connections to the same database, or multiple connections to the same or different database servers, all simultaneously. Each connection has its own associated transaction. You may get locking conflicts between your transactions if, for example, you modify the same record in the same database from two different connections.
is the login name you are using to make the connection.
indicates that you are connecting to Adaptive Server as a user.
is the ID of the user who is connecting.
indicates that the user will need to include a password when they connect.
is the password of the user connecting to Adaptive Server.
is the identifier you are using for the connection information.
is the string you are using for the connection information.
is the variable information for the host name and port.
is a list of parameter settings of the form keyword = value, separated by semicolons, and must be enclosed in single quotes.
Connects to a database from Interactive SQL. Interactive SQL prompts for a user ID and a password:
connect
Connects to the default database as DBA from Interactive SQL. Interactive SQL prompts for a password:
connect user "DBA"
As user dba
,
with password sql
, connects
to the pubs2 database of an Adaptive Server
running on host “tribble” at port number 5000:
connect to "tribble:5000" database pubs2 user dba identified by sql
As user dba
,
with password sql
, connects
to an Adaptive Server named “tribble” (defined
in interfaces file):
connect to tribble user dba identified by sql
connect establishes a connection to the database identified by database_name running on the server identified by engine_name.
No statements are allowed until a successful connect statement has been executed.
Interactive SQL behavior – if you do not specify a database or server in the connect statement, Interactive SQL remains connected to the current database, rather than to the default server and database. If you do specify a database name without a server name, Interactive SQL attempts to connect to the specified database on the current server. If you specify a server name without a database name, Interactive SQL connects to the default database on the specified server.
In the user interface, if the password or the user ID and password are not specified, the user is prompted to type the missing information.
When Interactive SQL is running in command-prompt mode (-nogui is specified when you start Interactive SQL from a command prompt) or batch mode, or if you execute connect without an as clause, an unnamed connection is opened. If there is another unnamed connection already opened, the old one is automatically closed. Otherwise, existing connections are not closed when you run connect.
Multiple connections are managed through the concept of a current connection. After a successful connect statement, the new connection becomes the current one. To switch to a different connection, use the set connection statement. Use the disconnect statement to drop connections.
In Interactive SQL, the connection information (including the database name, your user ID, and the database server) appears in the title bar above the SQL Statements pane. If you are not connected to a database, Not Connected appears in the title bar.
Any user can execute this command.