SqlConnectionStringBuilder.DataSource Tulajdonság

Definíció

Lekéri vagy beállítja a SQL Server példányának nevét vagy hálózati címét, amelyhez csatlakozni szeretne.

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

Tulajdonság értéke

A tulajdonság értéke DataSource , vagy String.Empty ha nincs megadva.

Attribútumok

Kivételek

Az érték null értékre való beállításához használja Valuea következőt: .

Példák

Az alábbi példa azt mutatja be, hogy a SqlConnectionStringBuilder osztály az "Adatforrás" kapcsolati karakterlánc kulcs szinonimáit jól ismert kulcssá alakítja:

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

Megjegyzések

Ez a tulajdonság az kapcsolati karakterlánc belüli "Adatforrás", "kiszolgáló", "cím", "addr" és "hálózati cím" kulcsoknak felel meg. Függetlenül attól, hogy ezek közül az értékek közül melyiket adták meg a megadott kapcsolati karakterlánc, a SqlConnectionStringBuilder által létrehozott kapcsolati karakterlánc a jól ismert "Adatforrás" kulcsot fogja használni.

A következőre érvényes:

Lásd még