Compartilhar via


IVsDataSourceSpecializer.DeriveSource Method

Derives a DDEX data source, when possible, from a DDEX provider-specific data connection string.

Namespace:  Microsoft.VisualStudio.Data.Core
Assembly:  Microsoft.VisualStudio.Data.Core (in Microsoft.VisualStudio.Data.Core.dll)

Syntax

'Declaration
Function DeriveSource ( _
    connectionString As String _
) As Guid
Guid DeriveSource(
    string connectionString
)
Guid DeriveSource(
    String^ connectionString
)
abstract DeriveSource : 
        connectionString:string -> Guid
function DeriveSource(
    connectionString : String
) : Guid

Parameters

  • connectionString
    Type: System.String

    A DDEX provider-specific data connection string that defines a target data source.

Return Value

Type: System.Guid
A valid, registered DDEX data source identifier that was determined to represent the type of the target data source identified by the connection string.

Exceptions

Exception Condition
ArgumentNullException

The connectionString parameter is nulla null reference (Nothing in Visual Basic).

Remarks

This is the most important method on the IVsDataSourceSpecializer interface. It enables DDEX clients to use just a DDEX provider identifier and data connection string to determine whether a provider has specialized support for the DDEX data source pointed to by information in the connection string. If this method returns a non-empty GUID, the client will typically turn around and call other methods on the interface, passing the DDEX data source identifier, to retrieve data source—specific implementations of support entities.

Examples

The following code demonstrates a basic implementation of this method for the Microsoft SQL Server DDEX provider. This provider supports two data sources: one is a SQL Server database and another is a SQL Server Express Edition database that uses a database file on the local computer. It determines that the data source should be a database file when there is an AttachDBFilename keyword in the connection string. (This example does not show the recommended approach, which would be to properly parse the string.) The example inherits from the framework DataSourceSpecializer class, which provides a default implementation of the other methods on the interface.

using System;
using Microsoft.VisualStudio.Data.Core;
using Microsoft.VisualStudio.Data.Framework;

public class MySourceSpecializer3 : DataSourceSpecializer
{
    private static readonly Guid s_sqlServerDataSource =
        new Guid("067EA0D9-BA62-43f7-9106-34930C60C528");
    private static readonly Guid s_sqlServerFileDataSource =
        new Guid("485C80D5-BC85-46db-9E6D-4238A0AD7B6B");

    public override Guid DeriveSource(string connectionString)
    {
        if (connectionString == null)
        {
            throw new ArgumentNullException("connectionString");
        }
        if (connectionString.Contains("AttachDBFilename"))
        {
            return s_sqlServerFileDataSource;
        }
        return s_sqlServerDataSource;
    }
}

.NET Framework Security

See Also

Reference

IVsDataSourceSpecializer Interface

Microsoft.VisualStudio.Data.Core Namespace