dotConnect for Oracle Documentation
Devart.Data.Oracle Namespace / OracleConnection Class / InfoMessage Event
Example

InfoMessage Event
Occurs when Oracle returns a warning or informational message.
Syntax
'Declaration
 
Public Event InfoMessage As OracleInfoMessageEventHandler
 
Event Data

The event handler receives an argument of type OracleInfoMessageEventArgs containing data related to this event. The following OracleInfoMessageEventArgs properties provide information specific to this event.

PropertyDescription
Gets the Oracle specific message code.  
Returns collection of errors generated by OracleCommand.  
Gets the full text of the message sent from the Oracle database.  
Gets the name of the application or the object that threw the event.  
Remarks

Clients that want to process warnings or informational messages sent by the server should create an OracleInfoMessageEventHandler delegate to listen to this event.

The InfoMessage event receives an InfoMessageEventArgs object containing, in its Errors property, a collection of the messages from the data source. You can query the Error objects in this collection for the error number and message text, as well as the source of the error. There are also details about the database, stored procedure, and line number that the message came from.

Example
The following example demostrates registering InfoMessage event handler that prints out the warning info.
class OracleInfoMessage {
        public static void WarningPrinter(object src,
                OracleInfoMessageEventArgs args)
        {
                Console.WriteLine("Source object is: " + src.GetType().Name);
                Console.WriteLine("InfoMessageArgs.Message is " + args.Message);
                Console.WriteLine("InfoMessageArgs.Source is " + args.Source);
        }
        static void Main()
        {
                OracleConnection con = new OracleConnection("User Id=scott;" +
                        "Password=tiger;Data Source=ora1110;");

                con.Open();

                OracleCommand cmd = con.CreateCommand();

                // Register to the InfoMessageHandler
                cmd.Connection.InfoMessage +=
                        new OracleInfoMessageEventHandler(WarningPrinter);

                cmd.CommandText = "CREATE OR REPLACE PACKAGE BODY PACKAGEWITHNOSPECIFICATION AS" +
                        "PROCEDURE GET_ALL_DEPTS (cur OUT SYS_REFCURSOR) AS" +
                        "BEGIN" +
                        " OPEN cur FOR SELECT * FROM DEPT;" +
                        "END;" +
                        "END PACKAGEWITHNOSPECIFICATION;";

                // Execute the statement that produces a warning
                cmd.ExecuteNonQuery();

                // Clean up
                cmd.Dispose();
                con.Dispose();
        }
}
Module Module1
        Public Sub WarningPrinter(ByVal src As Object, ByVal args As OracleInfoMessageEventArgs)
                Console.WriteLine("Source object is: " + src.GetType().Name)
                Console.WriteLine("InfoMessageArgs.Message is " + args.Message)
                Console.WriteLine("InfoMessageArgs.Source is " + args.Source)
        End Sub 'WarningPrinter
        Sub Main()
                Dim con As New OracleConnection("User Id=scott;Password=tiger;Data Source=ora1110;")
                con.Open()
                Dim cmd As OracleCommand = con.CreateCommand()
                ' Register to the InfoMessageHandler
                AddHandler cmd.Connection.InfoMessage, _
                New OracleInfoMessageEventHandler(AddressOf WarningPrinter)
                'command.Connection.InfoMessage += New OracleInfoMessageEventHandler(WarningPrinter)
                cmd.CommandText = "CREATE OR REPLACE PACKAGE BODY PACKAGEWITHNOSPECIFICATION AS" & _
                        "PROCEDURE GET_ALL_DEPTS (cur OUT SYS_REFCURSOR) AS" & _
                        "BEGIN" & _
                        " OPEN cur FOR SELECT * FROM DEPT;" & _
                        "END;" & _
                        "END PACKAGEWITHNOSPECIFICATION;"
                ' Execute the statement that produces a warning
                cmd.ExecuteNonQuery()

                ' Clean up
                cmd.Dispose()
                con.Dispose()
        End Sub
End Module
Requirements

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

See Also