SqlConnectionStringBuilder.DataSource Eigenschap

Definitie

Hiermee haalt u de naam of het netwerkadres op van het exemplaar van SQL Server waarmee u verbinding wilt maken.

public:
 property System::String ^ DataSource { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter(typeof(System.Data.SqlClient.SqlConnectionStringBuilder+SqlDataSourceConverter))]
public string DataSource { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Data.SqlClient.SqlConnectionStringBuilder+SqlDataSourceConverter))>]
member this.DataSource : string with get, set
Public Property DataSource As String

Waarde van eigenschap

De waarde van de DataSource eigenschap of String.Empty als er geen is opgegeven.

Kenmerken

Uitzonderingen

Als u de waarde wilt instellen op null, gebruikt u Value.

Voorbeelden

In het volgende voorbeeld ziet u dat de klasse SqlConnectionStringBuilder synoniemen voor de verbindingsreeks sleutel 'Gegevensbron' converteert naar de bekende sleutel:

using System.Data.SqlClient;

class Program
{
    static void Main()
    {
        SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(
            "Network Address=(local);Integrated Security=SSPI;" +
            "Initial Catalog=AdventureWorks");

        // Display the connection string, which should now
        // contain the "Data Source" key, as opposed to the
        // supplied "Network Address".
        Console.WriteLine(builder.ConnectionString);

        // Retrieve the DataSource property.
        Console.WriteLine("DataSource = " + builder.DataSource);

        Console.WriteLine("Press any key to continue.");
        Console.ReadLine();
    }
}
Imports System.Data.SqlClient

Module Module1

    Sub Main()
        Dim builder As _
         New SqlConnectionStringBuilder( _
         "Network Address=(local);Integrated Security=SSPI;" & _
         "Initial Catalog=AdventureWorks")

        ' Display the connection string, which should now 
        ' contain the "Data Source" key, as opposed to the 
        ' supplied "Network Address".
        Console.WriteLine(builder.ConnectionString)

        ' Retrieve the DataSource property:
        Console.WriteLine("DataSource = " & builder.DataSource)

        Console.WriteLine("Press any key to continue.")
        Console.ReadLine()
    End Sub
End Module

Opmerkingen

Deze eigenschap komt overeen met de sleutels 'Gegevensbron', 'server', 'adres', 'addr' en 'netwerkadres' in de verbindingsreeks. Ongeacht welke van deze waarden is opgegeven binnen de opgegeven verbindingsreeks, gebruikt de verbindingsreeks die door de SqlConnectionStringBuilder is gemaakt, de bekende sleutel 'Gegevensbron'.

Van toepassing op

Zie ook