次の方法で共有


How to: Define Connections to Remote Data Sources

You can define and store a connection to a remote data source in a Visual FoxPro database so you can use the connection name when you create and use a remote view.

Creating and storing a named connection in your database does not use any network or remote resources because Visual FoxPro does not activate the connection until you use the remote view. The named connection exists only as a connection definition stored as a row in the database (.dbc) file until the connection activates.

Note

Before you can create a connection, you must have a database open. For more information, see How to: Open Databases.

To define a connection

  1. Perform one of the following:

    • Open the database in the Database Designer.

    -OR-

    • Open the project for your application in the Project Manager.
  2. On the File menu, click New.

  3. In the New dialog box, click Connection, then New File.

  4. In the Connection Designer, select the options that correspond to your server requirements.

  5. On the File menu, click Save to open the Save dialog box.

  6. In the Connection Name box, type a name for the connection, and click OK.

For more information, see Connection Designer.

To create a new connection programmatically

  1. Open the database or the project containing the database.

  2. Choose one of the following:

    • To create a connection using the Connection Designer, use the CREATE CONNECTION command with a question mark (?).

    -OR-

    • To create a connection without opening the Connection Designer, use the CREATE CONNECTION command with the name of the connection and the necessary parameters.

For more information, see CREATE CONNECTION Command.

For example, the following code opens a database named MyDatabase and creates a connection called Remote_01 to a remote data source named SQLRemote:

OPEN DATABASE MyDatabase
CREATE CONNECTION Remote_01 ;
   DATASOURCE SQLRemote USERID myUserID PASSWORD myPassword

See Also

Tasks

How to: Create Remote Views

Concepts

Accessing Remote Data Using Views

View Creation

Other Resources

Creating Views

Working with Views (Visual FoxPro)