Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

26.2.3.6. The MySqlException Class

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.

26.2.3.6.1. Properties

The following properties are available:

  • HelpLink: Gets or sets a link to the help file associated with this exception.

  • InnerException: Gets the Exception instance that caused the current exception.

  • IsFatal: True if this exception was fatal and cause the closing of the connection, false otherwise.

  • Message: Gets a message that describes the current exception.

  • Number: Gets a number that identifies the type of error.

  • Source: Gets or sets the name of the application or the object that causes the error.

  • StackTrace: Gets a string representation of the frames on the call stack at the time the current exception was thrown.

  • TargetSite: Gets the method that throws the current exception.

26.2.3.6.2. Methods

The MySqlException class has no methods.

26.2.3.6.3. Usage

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

26.2.3.6.3.1. VB.NET

This example demonstrates how to use the MySqlException class with VB.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       
      
26.2.3.6.3.2. C#

This example demonstrates how to use the MySqlException class with C#:

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 );
   }
}
    

 
 
  Published under the terms of the GNU General Public License Design by Interspire