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作成された接続文字列は、既知の "データ ソース" キーを使用します。

適用対象

こちらもご覧ください