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. |
This sample shows how to detect and write to console warnings sent from database.
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