Advantage .NET Data Provider
Occurs when Advantage .NET Data Provider generates a warning or informational message.
public event AdsInfoMessageEventHandler InfoMessage;
With most errors generated by Advantage .NET Data Provider, either through error conditions caused by invalid use of the classes or by errors returned by Advantage Database Server, the Advantage .NET Data Provider will throw exceptions such as AdsException. For warning conditions, however, Advantage .NET Data Provider does not throw exceptions. Instead, it will fire an InfoMessage event to provide delegates with information about the warning.
Clients that want to process warnings or informational messages sent by the server should create an AdsInfoMessageEventHandler delegate to listen to this event.
The event handler receives an argument of type AdsInfoMessageEventArgs containing data related to this event.
// provide an event handler for InfoMessage events
protected static void OnAdsInfoMessage( object sender,
AdsInfoMessageEventArgs args )
{
// do something with the event
Console.WriteLine( "InfoMessage Event: " + args.Message );
}
public static void EventTest()
{
try
{
AdsConnection conn = new AdsConnection( "data source=c:\\data" );
conn.Open();
// set my event handler to listen
conn.InfoMessage += new
AdsInfoMessageEventHandler( OnAdsInfoMessage );
AdsCommand cmd = conn.CreateCommand();
// do an insert that causes a data truncation warning
cmd.CommandText = "insert into items( [product code] ) " +
"values( 'this is too long' )";
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine( e.Message );
}
}