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:
 property System::String ^ DataSource { System::String ^ get(); };
[System.ComponentModel.Browsable(true)]
[System.Data.DataSysDescription("SqlConnection_DataSource")]
public string DataSource { get; }
member this.DataSource : string
Public 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が "context connection = true" の場合、プロパティはを返します。The DataSource property returns null if the connection string for the SqlConnection is "context connection=true".

適用対象

こちらもご覧ください