SqlError.Class 属性

定义

获取从SQL Server返回的错误的严重级别。

public:
 property System::Byte Class { System::Byte get(); };
public byte Class { get; }
member this.Class : byte
Public ReadOnly Property Class As Byte

属性值

一个从 1 到 25 的值,指示错误的严重性级别。 默认值为 0。

示例

以下示例显示 SqlError 集合中的每个内容 SqlErrorCollection

public void DisplaySqlErrors(SqlException exception)
{
    for (int i = 0; i < exception.Errors.Count; i++)
    {
        Console.WriteLine("Index #" + i + "\n" +
            "Source: " + exception.Errors[i].Source + "\n" +
            "Number: " + exception.Errors[i].Number.ToString() + "\n" +
            "State: " + exception.Errors[i].State.ToString() + "\n" +
            "Class: " + exception.Errors[i].Class.ToString() + "\n" +
            "Server: " + exception.Errors[i].Server + "\n" +
            "Message: " + exception.Errors[i].Message + "\n" +
            "Procedure: " + exception.Errors[i].Procedure + "\n" +
            "LineNumber: " + exception.Errors[i].LineNumber.ToString());
    }
    Console.ReadLine();
}
Public Sub DisplaySqlErrors(ByVal exception As SqlException)
    Dim i As Integer

    For i = 0 To exception.Errors.Count - 1
        Console.WriteLine(("Index #" & i & ControlChars.NewLine & _
            "Source: " & exception.Errors(i).Source & ControlChars.NewLine & _
            "Number: " & exception.Errors(i).Number.ToString() & ControlChars.NewLine & _
            "State: " & exception.Errors(i).State.ToString() & ControlChars.NewLine & _
            "Class: " & exception.Errors(i).Class.ToString() & ControlChars.NewLine & _
            "Server: " & exception.Errors(i).Server & ControlChars.NewLine & _
            "Message: " & exception.Errors(i).Message & ControlChars.NewLine & _
            "Procedure: " & exception.Errors(i).Procedure & ControlChars.NewLine & _
            "LineNumber: " & exception.Errors(i).LineNumber.ToString()))
    Next i
    Console.ReadLine()
End Sub

注解

严重级别为 10 或更低级别的消息是信息性的,并指示用户输入的信息错误导致的问题。 从 11 到 16 的严重性级别由用户生成,可由用户更正。 从 17 到 25 的严重性级别表示软件或硬件错误。 发生级别 17、18 或 19 错误时,可以继续工作,尽管可能无法执行特定语句。

当严重级别为 19 或更少时,仍 SqlConnection 保持打开状态。 当严重级别为 20 或更大时,服务器通常会关闭 。SqlConnection 但是,用户可以重新打开连接并继续。 在这两种情况下,执行命令的方法将生成 a SqlException

有关SQL Server生成的错误的详细信息,请参阅 数据库引擎 事件和错误

适用于

另请参阅