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 实例的版本。

属性

例外

连接已关闭。

当返回的任务未完成,且在调用 OpenAsync(CancellationToken) 后未打开连接时,调用了 ServerVersion

示例

以下示例创建 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 正好是四位数。

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

适用于

另请参阅