Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - SQL Usage » Working with Database Objects » Working with databases

Starting a database Next Page

Connecting to a database


Before you can begin working with a database, you must connect to it.

When a database server is started, it assigns a unique connection ID to each new connection to it. You can obtain a user's connection-id using the CONNECTION_PROPERTY function to request the connection number. The following statement returns the connection ID of the current connection:

SELECT CONNECTION_PROPERTY( 'number' );
To connect to a database (Sybase Central)
  1. Choose Connections > Connect with SQL Anywhere 10.

    The Connect dialog appears.

  2. In the Connect dialog, specify the connection information, or ODBC data source name, to use to connect to the database, and then choose OK.

  3. To connect to a database (SQL)

For more information, see CONNECT statement [ESQL] [Interactive SQL].

Example 1

The following statement shows how to use CONNECT from Interactive SQL to connect to a database that has been started:

CONNECT to 'sample' DATABASE tempdb
AS conn1
USER 'DBA'
IDENTIFIED BY 'sql';

In this example, sample is the server name, tempdb is the database name, conn1 is the connection identifier, DBA is the user name, and sql is the password.

Example 2

The following statement shows how to use CONNECT in embedded SQL:

EXEC SQL CONNECT "DBA"
IDENTIFIED BY "sql";