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

SQL Anywhere 11.0.1 (Français) » UltraLite - C and C++ Programming » Application Development » Developing applications using Embedded SQL » Connecting to a database


Managing multiple connections

If you want more than one database connection in your application, you can either use multiple SQLCAs or you can use a single SQLCA to manage the connections.

To use multiple SQLCAs
♦  Managing multiple SQLCAs
  1. Each SQLCA used in your program must be initialized with a call to db_init and cleaned up at the end with a call to db_fini.

    See db_init function.

  2. The embedded SQL statement SET SQLCA is used to tell the SQL preprocessor to use a specific SQLCA for database requests. Usually, a statement such as the following is used at the top of your program or in a header file to set the SQLCA reference to point at task specific data:

    EXEC SQL SET SQLCA 'task_data->sqlca';

    This statement does not generate any code and does not affect performance. It changes the state within the preprocessor so that any reference to the SQLCA will use the given string.

    For more information about creating SQLCAs, see SET SQLCA statement [ESQL].

To use a single SQLCA

As an alternative to using multiple SQLCAs, you can use a single SQLCA to manage more than one connection to a database.

Each SQLCA has a single active or current connection, but that connection can be changed. Before executing a command, use the SET CONNECTION statement to specify the connection on which the command should be executed.

See SET CONNECTION statement [Interactive SQL] [ESQL].