SqlError Class
Collects information relevant to a warning or error returned by SQL Server.
Assembly: System.Data (in System.Data.dll)
The SqlError type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Class | Gets the severity level of the error returned from SQL Server. |
![]() | LineNumber | Gets the line number within the Transact-SQL command batch or stored procedure that contains the error. |
![]() | Message | Gets the text describing the error. |
![]() | Number | Gets a number that identifies the type of error. |
![]() | Procedure | Gets the name of the stored procedure or remote procedure call (RPC) that generated the error. |
![]() | Server | Gets the name of the instance of SQL Server that generated the error. |
![]() | Source | Gets the name of the provider that generated the error. |
![]() | State | Gets a numeric error code from SQL Server that represents an error, warning or "no data found" message. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Gets the complete text of the error message. (Overrides Object::ToString().) |
This class is created by the .NET Framework Data Provider for SQL Server 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, a SqlException is generated by the method executing the command.
For more information on errors generated by SQL Server, see SQL Server Books Online.
The following example displays each SqlError within the SqlErrorCollection collection.
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.
