State Property
Collapse the table of content
Expand the table of content

SqlError.State Property

 

Some error messages can be raised at multiple points in the code for the Database Engine. For example, an 1105 error can be raised for several different conditions. Each specific condition that raises an error assigns a unique state code.

Namespace:   System.Data.SqlClient
Assembly:  System.Data (in System.Data.dll)

public byte State { get; }

Property Value

Type: System.Byte

The state code.

State is only set for errors that are received from the server.

For more information on errors generated by SQL Server, see Understanding Database Engine Errors.

The following example displays each SqlError within the SqlErrorCollection collection.

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

.NET Framework
Available since 1.1
Return to top
Show:
© 2016 Microsoft