共用方式為


SqlConnectionStringBuilder.DataSource 屬性

定義

取得或設定要連接之 SQL Server 執行個體的名稱或網路位址。

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

屬性值

DataSource 屬性的值,如未提供任何值,則為 String.Empty

屬性

例外狀況

若要將值設定為 null,請使用 Value

範例

下列範例示範 SqlConnectionStringBuilder 類別如何將 "Data Source" 連接字串索引鍵的同義資料表轉換成已知的索引鍵:

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

備註

這個屬性會對應至連接字串中的 "Data Source"、"server"、"address"、"addr" 和 "network address" 索引鍵。 不論這些值在提供的 連接字串 內提供哪一個值,所SqlConnectionStringBuilder建立的 連接字串 都會使用已知的「數據源」索引鍵。

適用於

另請參閱