asp.net.ph

SqlException Class

System.Data.SqlClient Namespace


The exception that is thrown when a warning or error is returned by SQL Server.

SqlException Class Members

Collapse   Properties

Visibility Name Value Type Accessibility
public Class Byte [ Get ]
public ClientConnectionId Guid [ Get ]
public Errors SqlErrorCollection [ Get ]
public LineNumber Int32 [ Get ]
public Number Int32 [ Get ]
public Procedure String [ Get ]
public Server String [ Get ]
public Source String [ Get ]
public State Byte [ Get ]

Collapse   Methods

Visibility Name Parameters Return Type
public GetObjectData ( SerializationInfo si , StreamingContext context ) Void
public ToString ( ) String

Remarks

This class is created whenever the SQL Server™ .NET Data Provider encounters a situation that it cannot handle. SqlException always contains at least one instance of SqlError.

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 SQL Server™ Books Online. The SqlException class maps to SQL Server™ severity.

Example

The following example generates an SqlException due to a missing server, and then displays the exception.

void ThrowSqlException ( ) {
   string connString = "uid=sa; pwd=; database=northwind; server=badserver";
   SqlConnection myConn = new SqlConnection ( connString );
   try {
      myConn.Open ( );
   }
   catch ( SqlException myException ) {
      SqlErrorCollection myErrors = myException.Errors;
      for ( int i=0; i < myErrors.Count; i++ ) {
         Response.Write ( "Index #" + i + "<br>" +
            "Error: " + myErrors [ ].ToString ( ) + "<br>" );
      }
   }
}
  C# VB

See Also

SqlError   SqlErrorCollection Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph