The exception that is thrown when MySQL returns an error. This class cannot be inherited.
Namespace:
MySql.Data.MySqlClient
Assembly:
MySql.Data (in MySql.Data.dll) Version: 6.2.2.0
Syntax
C# |
---|
[SerializableAttribute] public sealed class MySqlException : DbException |
Visual Basic (Declaration) |
---|
<SerializableAttribute> _ Public NotInheritable Class MySqlException _ Inherits DbException |
Visual C++ |
---|
[SerializableAttribute] public ref class MySqlException sealed : public DbException |
Remarks
This class is created whenever the MySql Data Provider encounters an error generated from the server.
Any open connections are not automatically closed when an exception is thrown. If the client application determines that the exception is fatal, it should close any open MySqlDataReader objects or MySqlConnection objects.
Examples
The following example generates a MySqlException due to a missing server,
and then displays the exception.
CopyVB.NET
Public Sub ShowException() Dim mySelectQuery As String = "SELECT column1 FROM table1" Dim myConnection As New MySqlConnection ("Data Source=localhost;Database=Sample;") Dim myCommand As New MySqlCommand(mySelectQuery, myConnection) Try myCommand.Connection.Open() Catch e As MySqlException MessageBox.Show( e.Message ) End Try End Sub
CopyC#
public void ShowException() { string mySelectQuery = "SELECT column1 FROM table1"; MySqlConnection myConnection = new MySqlConnection("Data Source=localhost;Database=Sample;"); MySqlCommand myCommand = new MySqlCommand(mySelectQuery,myConnection); try { myCommand.Connection.Open(); } catch (MySqlException e) { MessageBox.Show( e.Message ); } }
Inheritance Hierarchy
System..::.Object
System..::.Exception
System..::.SystemException
System.Runtime.InteropServices..::.ExternalException
System.Data.Common..::.DbException
MySql.Data.MySqlClient..::.MySqlException
System..::.Exception
System..::.SystemException
System.Runtime.InteropServices..::.ExternalException
System.Data.Common..::.DbException
MySql.Data.MySqlClient..::.MySqlException