dotConnect for MySQL Documentation
Devart.Data.MySql Namespace / MySqlException Class / SqlState Property
Example

SqlState Property (MySqlException)
Returns a string containing the SQLSTATE error code for the last error.
Syntax
'Declaration
 
Public ReadOnly Property SqlState As String
 

Property Value

Error code for the last error.
Remarks

The error code consists of five characters. 00000 means "no error". The values are specified by ANSI SQL and ODBC.

This feature is available for MySQL servers 4.1.1 and newer.

Example
The sample shows how to retrieve error code in exception handler.
try 
{
  MySqlConnection connection = new MySqlConnection("User Id=test; Host=localhost; Port=3306; Database=test");
  connection.Open();
  MySqlCommand command = new MySqlCommand("insert into dept values (10,'test,'test')", connection);
  command.ExecuteNonQuery();
  command.ExecuteNonQuery();
}
catch (MySqlException ex) 
{
  Console.WriteLine("Message: " + ex.Message);
  Console.WriteLine("Code: " + ex.Code.ToString());
  Console.WriteLine("SqlState: " + ex.SqlState);
}
Try
  Dim connection As MySqlConnection = New MySqlConnection("User Id=test; Host=localhost; Port=3306; Database=test")
  connection.Open()
  Dim Command As MySqlCommand = New MySqlCommand("insert into dept values (10,'test,'test')", connection)
  Command.ExecuteNonQuery()
  Command.ExecuteNonQuery()
Catch ex As MySqlException
  Console.WriteLine("Message: " + ex.Message)
  Console.WriteLine("Code: " + ex.Code.ToString())
  Console.WriteLine("SqlState: " + ex.SqlState)
End Try
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also