Establishes a connection to a database.
Syntax one
connect [to Adaptive_Server_name] [database database_name] [as connection_name] [user] user_id [identified by password]
Syntax two
connect using connect_string connect_string : { identifier | string | hostvar}
Adaptive_Server_name – the name of the server to which you are connecting.
database_name – is the name of the database to which you are connecting. It must conform to the rules for identifiers and cannot be a variable.
as clause – 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.
connection_name – the login name you are using to make the connection.
user – indicates that you are connecting to Adaptive Server as a user.
user_id – the ID of the user who is connecting.
identified by password – indicates that the user will need to include a password when they connect.
password – the password of the user connecting to Adaptive Server.
identifier – the identifier you are using for the connection information.
string – the string you are using for the connection information.
hostvar – variable information for the host name and port.
Syntax two – A connect_string is a list of parameter settings of the form keyword= value, separated by semicolons, and must be enclosed in single quotes.
Connect to a database from Interactive SQL. Interactive SQL prompts for a user ID and a password.
connect
As user sa
,
with password sybase
, connect
to the pubs2 database of an Adaptive Server
running on host “tribble” at port number 5000:
connect to ASE "tribble:5000" database pubs2 user sa identified by sybase
As user sa
,
with password sybase
, connect
to an Adaptive Server named “tribble” (defined
in interfaces file):
connect to ASE tribble user sa identified by sybase
Once you connect to Adaptive Server, the server name, database name, and your user ID appear on the title bar, for example: “pubs2 (dbo) on tribble” would appear for the example above.
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 run this command.
None.
disconnect, set connection