SqlConnection.DataSource SqlConnection.DataSource SqlConnection.DataSource SqlConnection.DataSource Property

定義

接続先となる SQL Server のインスタンスの名前を取得します。Gets the name of the instance of SQL Server to which to connect.

public:
 virtual property System::String ^ DataSource { System::String ^ get(); };
[System.ComponentModel.Browsable(true)]
[System.Data.DataSysDescription("SqlConnection_DataSource")]
public override string DataSource { get; }
member this.DataSource : string
Public Overrides ReadOnly Property DataSource As String

プロパティ値

接続先となる SQL Server のインスタンスの名前。The name of the instance of SQL Server to which to connect. 既定値は空の文字列です。The default value is an empty string.

次の例では、作成、SqlConnectionし、一部の読み取り専用プロパティを表示します。The following example creates a SqlConnection and displays some of its read-only properties.

private static void OpenSqlConnection(string connectionString)
{
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        connection.Open();
        Console.WriteLine("ServerVersion: {0}", connection.ServerVersion);
        Console.WriteLine("DataSource: {0}", connection.DataSource);
    }
}
Private Sub OpenSqlConnection(ByVal connectionString As String)
    Using connection As New SqlConnection(connectionString)
        connection.Open()
        Console.WriteLine("ServerVersion: {0}", connection.ServerVersion)
        Console.WriteLine("DataSource: {0}", connection.DataSource)
    End Using
End Sub

注釈

注意

DataSourceプロパティが返すnull場合、接続文字列が、SqlConnectionは"コンテキスト接続 = true"です。The DataSource property returns null if the connection string for the SqlConnection is "context connection=true".

適用対象

こちらもご覧ください