This documentation is archived and is not being maintained.

SqlError.Class Property

Gets the severity level of the error returned from SQL Server.

[Visual Basic]
Public ReadOnly Property Class As Byte
[C#]
public byte Class {get;}
[C++]
public: __property unsigned char get_Class();
[JScript]
public function get Class() : Byte;

Property Value

A value from 1 to 25 that indicates the severity level of the error. The default is 0.

Remarks

Messages with a severity level of 10 or less are informational and indicate problems caused by mistakes in information that a user has entered. Severity levels from 11 through 16 are generated by the user, and can be corrected by the user. Severity levels from 17 through 25 indicate software or hardware errors. When a level 17, 18, or 19 error occurs, you can continue working, although you might not be able to execute a particular statement.

The SqlConnection remains open when the severity level is 19 or less. When the severity level is 20 or greater, the server usually closes the SqlConnection. However, the user can reopen the connection and continue. In both cases, a SqlException is generated by the method executing the command.

For information on the warning and informational messages sent by SQL Server, see the Troubleshooting section of the SQL Server documentation.

Example

[Visual Basic, C#, C++] The following example displays each SqlError within the SqlErrorCollection collection.

[Visual Basic] 
Public Sub DisplaySqlErrors(myException As SqlException)
    Dim i As Integer
    For i = 0 To myException.Errors.Count - 1
        MessageBox.Show(("Index #" & i & ControlChars.NewLine & _
                         "Source: " & myException.Errors(i).Source & ControlChars.NewLine & _
                         "Number: " & myException.Errors(i).Number.ToString() & ControlChars.NewLine & _
                         "State: " & myException.Errors(i).State.ToString() & ControlChars.NewLine & _
                         "Class: " & myException.Errors(i).Class.ToString() & ControlChars.NewLine & _
                         "Server: " & myException.Errors(i).Server & ControlChars.NewLine & _
                         "Message: " & myException.Errors(i).Message & ControlChars.NewLine & _
                         "Procedure: " & myException.Errors(i).Procedure & ControlChars.NewLine & _
                         "LineNumber: " & myException.Errors(i).LineNumber.ToString()))
    Next i
End Sub 'DisplaySqlErrors

[C#] 
public void DisplaySqlErrors(SqlException myException) 
 {
    for (int i=0; i < myException.Errors.Count; i++)
    {
       MessageBox.Show("Index #" + i + "\n" +
            "Source: " + myException.Errors[i].Source + "\n" +
            "Number: " + myException.Errors[i].Number.ToString() + "\n" +
            "State: " + myException.Errors[i].State.ToString() + "\n" +
            "Class: " + myException.Errors[i].Class.ToString() + "\n" +
            "Server: " + myException.Errors[i].Server + "\n" +
            "Message: " + myException.Errors[i].Message + "\n" +
            "Procedure: " + myException.Errors[i].Procedure + "\n" +
            "LineNumber: " + myException.Errors[i].LineNumber.ToString());
    }
 }

[C++] 
public:
void DisplaySqlErrors(SqlException* myException) 
 {
    for (int i=0; i < myException->Errors->Count; i++)
    {
       MessageBox::Show(String::Concat(
          String::Format( S"Index #{0}\nSource: {1}\nNumber: {2}\n",
             __box(i), myException->Errors->Item[i]->Source, __box(myException->Errors->Item[i]->Number) ),
          String::Format( S"State: {0}\nClass: {1}\nServer: {2}\n",
             __box(myException->Errors->Item[i]->State), __box(myException->Errors->Item[i]->Class), myException->Errors->Item[i]->Server ),
          String::Format( S"Message: {0}\nProcedure: {1}\nLineNumber: {2}",
             myException->Errors->Item[i]->Message, myException->Errors->Item[i]->Procedure, __box(myException->Errors->Item[i]->LineNumber) )));
    }
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

SqlError Class | SqlError Members | System.Data.SqlClient Namespace | Number | State | Server | Source | Message | Procedure | LineNumber

Show: