SqlConnection.ServerVersion 屬性

定義

取得字串,其中包含用戶端連線的 SQL Server 執行個體版本。

public:
 virtual property System::String ^ ServerVersion { System::String ^ get(); };
public:
 property System::String ^ ServerVersion { System::String ^ get(); };
public override string ServerVersion { get; }
[System.ComponentModel.Browsable(false)]
[System.Data.DataSysDescription("SqlConnection_ServerVersion")]
public string ServerVersion { get; }
[System.ComponentModel.Browsable(false)]
public override string ServerVersion { get; }
member this.ServerVersion : string
[<System.ComponentModel.Browsable(false)>]
[<System.Data.DataSysDescription("SqlConnection_ServerVersion")>]
member this.ServerVersion : string
[<System.ComponentModel.Browsable(false)>]
member this.ServerVersion : string
Public Overrides ReadOnly Property ServerVersion As String
Public ReadOnly Property ServerVersion As String

屬性值

SQL Server 實例的版本。

屬性

例外狀況

連接關閉。

傳回的工作未完成時即已呼叫 ServerVersion,而且在呼叫 OpenAsync(CancellationToken) 之後未開啟連接。

範例

下列範例會 SqlConnection 建立 並顯示 ServerVersion 屬性。

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

備註

版本的格式為 ##.##.####,其中前兩位數是主要版本、接下來兩位數是次要版本,最後四位數是發行版本。 此字串的格式為 major.minor.build,其中 major 和 minor 正好是兩位數,而組建剛好是四位數。

傳回的工作未完成時即已呼叫 ServerVersion,而且在呼叫 OpenAsync 之後未開啟連接。

適用於

另請參閱