Freigeben über


How to: Retrieve a Connection Using Existing Connection Data

To retrieve a DDEX IVsDataConnection object instance for which there is existing connection data, the client must retrieve the connection data and pass it to the appropriate method. Connection data consists of the DDEX provider, which is specified by a GUID and connection string. There are three scenarios under which you could obtain a connection by using existing connection data:

  • Retrieve a new or existing connection by using the IVsDataConnectionManager service with connection data provided by the DDEX client.

  • Retrieve a new connection with existing connection data by using the IVsDataConnectionFactory service.

  • Retrieve a connection wrapping an existing non-DDEX provider object with data provided by using the IVsDataConnectionFactory service.

In cases where a new connection is being created by using user inputs, see How to: Retrieve a Connection Based on User Input.

Scenario One

Scenario one involves retrieving an existing connection object by using the IVsDataConnectionManager and the appropriate connection data. In cases where no connection is currently being managed, the connection manager returns a new connection. If, on the other hand, the connection manager is currently managing a connection object that is equivalent to the specified one, it returns this connection object.

To open an existing connection by using the DataConnectionManager Service

  1. Call the GetConnection method on the IVsDataConnectionManager class.

  2. Pass in the DDEX provider (Guid), the connection string (String), and a Boolean value indicating whether the connection string is encrypted.

    This returns the specified connection object, if this or an equivalent connection are currently being managed. Alternatively, it returns a new connection object with the specified connection data.

Scenario Two

In scenario two, a new connection is both created and retrieved by using the IVsDataConnectionFactory, again providing the appropriate DDEX provider guid, connection string, and the Boolean parameter mentioned in scenario one.

To open a new connection by using the DataConnectionFactory Service

  1. Call the CreateConnection on the IVsDataConnectionFactory class.

  2. Pass in the DDEX provider (Guid), the connection string (String), and a Boolean value indicating whether the connection string is encrypted.

    This returns an isolated connection object available only to the client that creates it.

Scenario Three

In scenario three, a client who uses a non-DDEX connection object wants to access DDEX functionality from within the connection. For example, a DDEX implementation has a SQL connection that uses a standard ADO.NET SQL connection object, but it wants to use certain DDEX features. To do this, it must create a DDEX connection by using the underlying provider object (ADO.NET, in this case) and wrap it in a DDEX connection by using the MakeConnectionFrom method.

To wrap an existing provider object by using the DataConnectionFactory Service

  1. Create the underlying non-DDEX provider object.

  2. Call the MakeConnectionFrom method on the IVsDataConnectionFactory class.

  3. Pass in the non-DDEX provider object instance (Object) and provider guid.

    This creates a DDEX connection object that wraps the underlying provider object.

    Note

    Calling the Dispose method on this data connection does not destroy the underlying non-DDEX provider object.

    Important

    The DDEX provider you select to wrap your underlying connection object must be able to understand the object it wraps. This makes selecting the DDEX provider object important.

See Also

Tasks

How to: Retrieve a Connection Based on User Input

Reference

GetConnection

IVsDataConnectionManager

IVsDataConnectionFactory

CreateConnection

MakeDataConnectionFrom