System.Data.SqlClient Namespace
Collects information relevant to a warning or error returned by SQL Server.
This class is created by the SQL Server™ .NET Data Provider when an error occurs. An instance of SqlError is created and managed by the SqlErrorCollection, which in turn is created by the SqlException class.
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, an 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.
The following example displays each SqlError within the SqlErrorCollection.
public void DisplaySqlErrors ( SqlException myException ) {
for ( int i=0; i < myException.Errors.Count; i++ ) {
Response.Write ( "Index #" + i + "<br>" +
"Error: " + myException.Errors [ ].ToString ( ) + "<br>" );
}
}
Public Sub DisplaySqlErrors ( myException As SqlException )
Dim i As Integer
For i = 0 To myException.Errors.Count - 1
Response.Write ( "Index #" & i & ControlChars.Cr & _
"Error: " & myException.Errors ( i ).ToString ( ) & ControlChars.Cr )
Next i
End Sub |
|
C# |
VB |
SqlErrorCollection SqlException