通过


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 格式,其中主版本和次要版本正好是两位数,生成正好是四位数字。

ServerVersion 在返回的任务未完成时调用,并在调用 OpenAsync后未打开连接。

适用于

另请参阅