Gets the severity level of the error returned from the .NET Framework Data Provider for SQL Server.
Assembly: System.Data (in System.Data.dll)
Messages that have 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 ordinarily 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 about the warning and informational messages sent by SQL Server, see the Troubleshooting section of the SQL Server documentation.
Public Sub ShowSqlException(ByVal connectionString As String) Dim queryString As String = "EXECUTE NonExistantStoredProcedure" Dim errorMessages As New StringBuilder() Using connection As New SqlConnection(connectionString) Dim command As New SqlCommand(queryString, connection) Try command.Connection.Open() command.ExecuteNonQuery() Catch ex As SqlException Dim i As Integer For i = 0 To ex.Errors.Count - 1 errorMessages.Append("Index #" & i.ToString() & ControlChars.NewLine _ & "Message: " & ex.Errors(i).Message & ControlChars.NewLine _ & "LineNumber: " & ex.Errors(i).LineNumber & ControlChars.NewLine _ & "Source: " & ex.Errors(i).Source & ControlChars.NewLine _ & "Procedure: " & ex.Errors(i).Procedure & ControlChars.NewLine) Next i Console.WriteLine(errorMessages.ToString()) End Try End Using End Sub
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.