SqlConnection.ServerVersion 屬性
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得字串,其中包含用戶端連線的 SQL Server 執行個體版本。
public:
virtual property System::String ^ ServerVersion { System::String ^ get(); };
public:
property System::String ^ ServerVersion { System::String ^ get(); };
C#
public override string ServerVersion { get; }
C#
[System.ComponentModel.Browsable(false)]
[System.Data.DataSysDescription("SqlConnection_ServerVersion")]
public string ServerVersion { get; }
C#
[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 屬性。
C#
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 之後未開啟連接。
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, 6 (package-provided), 7 (package-provided), 8 (package-provided), 9 (package-provided), 10 (package-provided) |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
- SQL Server and ADO.NET (SQL Server 和 ADO.NET)
-
ADO.NET 概觀