On this page
CONNECT
Opens a connection to a database, or sets the API session context with CONNECT API.
Syntax
CONNECT <connection>
CONNECT $CDF
CONNECT API <api>:<environment>
Quick start
SHOW ALL CONNECTIONS;
CONNECT WORLD;
Lists the connections, then opens WORLD.
Arguments
| Argument | Required | Values | Default |
|---|---|---|---|
<connection> | Yes, for a database | The ID of an active connection of the CDF | None |
$CDF | Yes, for CDF maintenance | Opens CDF maintenance mode after asking for the master password | None |
API <api>:<environment> | Yes, for an API | An active imported API and one of its active environments | None |
Examples
CONNECT db01;
OPEN WORLD;
CONNECT API DESK_DEFINITION:PROD;
Example session
BroadSQL> SELECT * FROM COUNTRY;
ERROR: No active database connection.
Use CONNECT <connection> first.
BroadSQL> CONNECT WORLD;
WORLD>
Details
Connecting to a database
The connection ID must be an active connection of the Connections Definition File (CDF); an inactive one is refused with a message saying how to reactivate it. CONNECT works from the BroadSQL> prompt, when no database is connected, as from any connection.
- The new connection is opened first. If that fails, the command reports it and the current connection stays open, with the same prompt.
- On success, the current connection is closed and the prompt shows the new one.
SHOW DBINFOSandSHOW AUTOCOMMITsummarize the new connection, then its login script runs. - When logging is on by default, the session is written to the query log file.
- A connection whose URL opens BroadSQL's own configuration database (the CDF), under any name or path, or a copy of the CDF, is refused: the CDF is never an ordinary connection.
CDF maintenance: CONNECT $CDF
CONNECT $CDF asks for the master password, every time, then opens CDF maintenance mode: a direct SQL session on the configuration database, for diagnosis and repair, with the prompt $CDF [MAINTENANCE]>. It must be typed at the prompt (it is refused in a Script, a REPEAT and an Editor run) and takes no argument. A wrong or empty password changes nothing. DISCONNECT leaves maintenance mode. For normal configuration changes, use CONFIG and the connection commands instead. CONNECT <id> always means a connection, never an Environment: to switch by Environment within the current Database Group, use ENV <environment>, which opens the connection exactly the same way.
Missing JDBC driver
When no JDBC driver is available for the connection's database type, the test fails with an error naming the missing driver class. Copy the matching driver .jar file into the drivers/ or lib/ folder, restart BroadSQL and try again.
API session context
CONNECT API <api>:<environment> sets the API and environment that RUN and SHOW ENDPOINTS use when the command line does not repeat them. The API and its environment must exist and be active. The two contexts are independent: connecting to an API never closes the database connection, and connecting to a database never clears the API context. The prompt shows both when both are active, for example WORLD [API DESK:PROD]>. DISCONNECT API clears only the API context.
Related
- DISCONNECT
- ENV:
ENV <environment>switches to another Environment of the current Database Group - SHOW ALL CONNECTIONS
- PING, test without connecting
- Connections
- Starting, connecting and logging out
- CDF maintenance mode
Used in these how-tos
- How do I find the rows that differ between two databases?
- How do I export tables and query results with DUMP? A step-by-step tutorial
- How do I keep a local copy of a production table up to date?
- How do I investigate a support ticket and keep the evidence?
- How do I verify that a data fix changed only the intended rows?
- Rows missing between two databases (template, WORLD and WORLD-QA) Scripts Gallery
Last modified in release development.
Found something wrong or unclear on this page? Tell us, with the page address.