Command CREATE CONNECTION Professional
Create a connection and connect to a data source
Syntax
CREATE CONNECTION
INTO <oSession>
DATASOURCE <dsn>
[DATABASE <db>]
[USERID <user>]
[PASSWORD <pwd>]
[DIALOG
[PARENT <parent>]]
or
CREATE CONNECTION
INTO <oSession>
CONNSTRING <cons>
[DIALOG
[PARENT <parent>]]
Parameters
INTO <oSession>
The <oSession> is a variable that holds the connection (the session object). It can be used later to refer to the connection.
<dsn>
The <dsn> is the name of a DSN that should be used to establish the connection.
<db>
If the optional argument <db> is provided, the connection string will be passed the name of the database explicitly. If the DSN is not preconfigured to point to a database, this parameter should be supplied.
<user>
The argument <user> specifies the user identification for the ODBC data source.
<pwd>
The argument <pwd> specifies the password for the ODBC data source.
<cons>
Specifies a connection string for the ODBC data source. The connection string can be used instead of explicitly including the ODBC data source, the user identification, and the password.
DIALOG
The ODBC driver will popup a dialog requesting information to successfully connect to the ODBC data source. If the <dsn> does not exists, or the <cons> parameter contains unknown driver names, the Connection Manager will be popped up to select a connection before. If <user> and or <pwd> are required to login, the ODBC driver will popup a login dialog to be able to connect.
<parent>
The dialog to be shown will use <parent> as the parent window which affects the initial window position of this dialog and the window modality.
Description
The command CREATE CONNECTION creates a connection to the specified ODBC data source, either by supplied a DSN and optional additional information or by specifying a valid connection string.
Examples
// This example shows how to use the
// CREATE CONNECTION command.
#include "sqlcmd.ch"
PROCEDURE main(cDsn)
LOCAL cConnStr, myConn
// use an ODBC data source name to connect,
// provide user name and password
CREATE CONNECTION INTO myconn DATASOURCE "Oracle-Demo" ;
USERID "Scott" PASSWORD "Tiger"
DELETE CONNECTION myconn
// specify a full connection string if
// all parameters of the data source are to be supplied
// or no datasource exists
CREATE CONNECTION INTO myconn CONNSTRING ;
"DSN=dBASE-Files;DefaultDir=C:\dbase;"+;
"DriverId=21;FIL=dBase III;MaxBufferSize=2048;PageTimeout=5"
DELETE CONNECTION myconn
// specify a variable holding a connection string
TEXT INTO cConnStr WRAP ";"
DRIVER=Microsoft Excel Driver (*.xls)
FIL=excel 8.0
DBQ=testdb.xls
ENDTEXT
CREATE CONNECTION INTO myconn CONNSTRING (cConnStr)
// now get some data
SQL "SELECT * FROM customers"
DO WHILE !EOF
? FirstName, LastName, City
SKIP
ENDDO
DELETE CONNECTION myconn
RETURN
PROCEDURE DbeSys
DbeLoad( "ODBCDBE" )
DbeSetDefault( "ODBCDBE" )
RETURN
Feedback
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.