'Declaration Public Event InfoMessage As MySqlInfoMessageEventHandler
public event MySqlInfoMessageEventHandler InfoMessage
The event handler receives an argument of type MySqlInfoMessageEventArgs containing data related to this event. The following MySqlInfoMessageEventArgs properties provide information specific to this event.
Property | Description |
---|---|
Code | Gets a code that identifies the type of error. |
Message | Gets the text describing the error. |
Clients that want to process warnings or informational messages sent by the server should create a MySqlInfoMessageEventHandler delegate to listen to this event.
The event, when fired, provides information about how many warnings were issued during execution of a MySqlCommand. Delegates should issue "SHOW WARNINGS" SQL statement to retrieve extended information, which is warning type, code, and message from server. The statement must be executed using the same MySqlConnection that generated the event.
This feature is available only in MySQL versions 4.1.0 and newer.
static void OnInfoMessage(object sender, Devart.Data.MySql.MySqlInfoMessageEventArgs e) { Console.WriteLine(e.Message); MySqlCommand myCommand = new MySqlCommand("SHOW WARNINGS",(MySqlConnection)sender); MySqlDataReader reader = myCommand.ExecuteReader(); while(reader.Read()) { Console.WriteLine(reader[0].ToString() +" "+ reader[1].ToString() +" "+ reader[2].ToString()); } } [STAThread] static void Main(string[] args) { MySqlConnection myConn = new MySqlConnection("User Id=test; Host=localhost; Port=3306; Database=test"); myConn.Open(); myConn.InfoMessage += new MySqlInfoMessageEventHandler(OnInfoMessage); MySqlCommand command = new MySqlCommand("DROP TABLE IF EXISTS no_such_table", myConn); command.ExecuteNonQuery(); myConn.Close(); Console.WriteLine("Get it?"); Console.ReadLine(); }
Sub Main() Dim myConn As MySqlConnection = New MySqlConnection("User Id=test; Host=localhost; Port=3306; Database=test") myConn.Open() AddHandler myConn.InfoMessage, New MySqlInfoMessageEventHandler(AddressOf OnInfoMessage) Dim Command As MySqlCommand = New MySqlCommand("DROP TABLE IF EXISTS no_such_table", myConn) Command.ExecuteNonQuery() myConn.Close() Console.WriteLine("Get it?") Console.ReadLine() End Sub Sub OnInfoMessage(ByVal sender As Object, ByVal e As Devart.Data.MySql.MySqlInfoMessageEventArgs) Console.WriteLine(e.Message) Dim myCommand As MySqlCommand = New MySqlCommand("SHOW WARNINGS", CType(sender, MySqlConnection)) Dim reader As MySqlDataReader = myCommand.ExecuteReader() While reader.Read() Console.WriteLine(reader(0).ToString() & " " & reader(1).ToString() & " " & reader(2).ToString()) End While End Sub
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