共用方式為


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 正好是兩位數,build 則是四位數。

ServerVersion 當返回任務未完成且呼叫未 OpenAsync開啟連線時,被呼叫。

適用於

另請參閱