Compartilhar via


How to: Retrieve a Connection Based on User Input

To retrieve a DDEX data source connection object, you must provide connection data in the form of a DDEX provider. The provider is specified by its GUID and connection string. Users can specify the provider and connection string in the Data Connection dialog box.

In cases where a connection is made using existing connection data, see How to: Retrieve a Connection Using Existing Connection Data.

To retrieve a connection with user inputs

  1. Retrieve the dialog factory service by calling the CreateConnectionDialog method on the IVsDataConnectionDialogFactory interface.

    This returns a IVsDataConnectionDialog object instance.

  2. Set properties, as needed, on the IVsDataConnectionDialog object.

  3. Display the connection dialog box by calling either of two ShowDialog methods on the IVsDataConnectionDialog interface:

    1. ShowDialog. Use this method when you intend to store connection-string data independently of actually creating the connection. On clicking OK, the client gets back the connection data supplied in the dialog box and stores it in whichever manner it wishes. A subsequent call to the CreateDataConnection method passes the connection data retrieved from the dialog box to the method to create a connection object.

      - or -

    2. ShowDialog. Use this method to request the dialog box so the user can:

      Enter new connection data (provider guid and connection string).

      -or-

      Locate an existing connection object by using values provided by the user.

      In both cases, the connection object is retrieved from the IVsDataConnectionManager service, which returns an existing connection object if it (or one that is equivalent) is currently being managed. Otherwise, it returns a new connection object.

      If the Boolean parameter returns false, the connection is returned in its current state (that is, closed if this is a new connection). If the parameter returns true, the dialog box confirms that the returned connection is open before returning to the caller.

  4. Use DDEX connection services to use the data connection.

See Also

Tasks

How to: Retrieve a Connection Using Existing Connection Data

Concepts

DDEX Data Connection UI