Partilhar via


CREATE CONNECTION Command

Creates a named connection and stores it in the current database.

CREATE CONNECTION [ConnectionName | ?]   [DATASOURCE cDataSourceName]
   [USERID cUserID] [PASSWORD cPassWord]   [DATABASE cDatabaseName]   
| CONNSTRING cConnectionString]

Parameters

  • ConnectionName
    Specifies the name of the connection to create.
  • ?
    Displays the Connection Designer from which you can create and save a connection.
  • DATASOURCE cDataSourceName
    Specifies the name of the ODBC data source for the connection.
  • USERID cUserID
    Specifies your user identification for the ODBC data source.
  • PASSWORD cPassWord
    Specifies your password for the ODBC data source.
  • DATABASE cDatabaseName
    Specifies a database on the server to which the connection is made.
  • CONNSTRING cConnectionString
    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.

Remarks

If you omit the optional arguments, the Connection Designer appears, allowing you to interactively create a connection.

Example

The following example assumes an ODBC data source called MyFoxSQLNT is available, and the user ID for the data source is "sa." The testdata database is opened, and a connection named Myconn is created. DISPLAY CONNECTIONS is used to display the named connections in the database. The connection is then removed from the database with DELETE CONNECTION.

CLOSE DATABASES
OPEN DATABASE (HOME(2) + 'data\testdata')
CREATE CONNECTION Myconn DATASOURCE "MyFoxSQLNT" USERID "sa"

CLEAR
DISPLAY CONNECTIONS  && Displays named connections in the database
DELETE CONNECTION Myconn  && Removes the connection just created

See Also

DELETE CONNECTION | DBGETPROP( ) | DISPLAY CONNECTIONS | LIST CONNECTIONS | MODIFY CONNECTION | OPEN DATABASE | RENAME CONNECTION