Programming Guide |
Creates a named connection to a database engine
DBMS [WITH ENGINEengine
] DECLAREconnection
CONNECTION
[WITHoption
=argVar
[,... ]]DBMS [WITH ENGINEengine
] DECLAREconnection
CONNECION
[FORoption arg
...]
WITH ENGINE
engine
- Name of engine to associate with the connection. If the clause is not used, Panther opens the connection on the default engine.
connection
- Name of connection to be opened.
option
- Name of connection option. Names and number of available options is engine-specific.
argVar
- Variable that contains the value assigned to the option, or a quoted string. Use this variant when the value might contain spaces and/or punctuation. Spaces are permitted around the equal sign.
arg
- Literal value, either a quoted string or a colon-expanded expression, assigned to the connection option.
DBMS DECLARE CONNECTION
opens a session on a database engine. If the statement executes successfully, it allocates a connection structure and adds it to the list of open structures.Applications which must connect to two or more database servers should declare a named connection to each server. If you are connecting to two or more database engines, you must declare a connection for each engine.
The combination of necessary or supported options is engine-specific. Common options include
USER
,PASSWORD
,DATABASE
, andSERVER
. For a list of the valid options, refer to "Database Drivers."Options can be specified using either of two ways:
WITH
variant (recommended)—The option and its argument value are separated by an equal sign (spaces are permitted), option-value pairs are comma-separated, and if the argument is a variable, it is not enclosed in quotes (and not colon-expanded). If the argument is a string, it is enclosed in quotes; spaces and special punctuation characters are permitted.
Since the variables are not colon-expanded, this variant prevents the values of variables from appearing in error messages or trace statements.
The connection remains open until it is closed with
CLOSE CONNECTION
orCLOSE_ALL_CONNECTIONS
.For additional information, refer to Chapter 8, "Connecting to Databases," in Application Development Guide.
// This procedure connects to the database and has// two variables for the user and password.proc logonDBMS DECLARE c1 CONNECTION \
WITH USER=user, PASSWORD=pword, \
DATABASE="C:\Program Files\video\videobiz"
return// Same example as above, but using FOR rather
// than WITH. Note that the variable names are
// quoted and colon-expanded.proc logon
DBMS DECLARE c1 CONNECTION \
FOR USER ":user" PASSWORD ":pword" \
DATABASE "C:\Progra~1\video\videobiz"
return
CLOSE CONNECTION
,CLOSE_ALL_CONNECTIONS
,CONNECTION
,WITH CONNECTION
,dm_get_db_conn_handle
,dm_is_connection