See Also

OracleConnection Class  | OracleConnection Members

Language

Visual Basic

C#

Show All

See AlsoLanguagesDevart.Data.OracleSend comments on this topic.

InfoMessage Event

Devart.Data.Oracle Namespace > OracleConnection Class : InfoMessage Event

Occurs when Oracle returns a warning or informational message.

[Visual Basic]
Public Event InfoMessage() As OracleInfoMessageEventHandler
[C#]
public event OracleInfoMessageEventHandler InfoMessage();

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
CodeGets the Oracle specific message code.
ErrorsReturns collection of errors generated by OracleCommand.
MessageGets the full text of the message sent from the Oracle database.
SourceGets 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 __Delegates.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.

[C#] 

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

[Visual Basic] 

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

See Also

OracleConnection Class  | OracleConnection Members

 

 


© 2002 - 2013 Devart. All Rights Reserved.