ConnectionOpen
This event is triggered upon the OracleConnection.Open()
method or a connection opening to undertake Application Continuity failover and replay.
Declaration
// C# public event OracleConnectionOpenEventHandler ConnectionOpen;
Event Data
The event handler receives a OracleConnectionOpenEventArgs
object which exposes the following property containing information about the ConnectionOpen
event.
-
Connection
OracleConnection
object on whichOpen()
is called.
Exceptions
-
InvalidOperationException()
- ifCPVersion=1.0
and theConnectionOpen
event is used. Applies to unmanaged ODP.NET only. -
InvalidOperationException()
- if theConnectionOpen
event is set after opening a connection.
Remarks
This feature requires CPVersion=2.0
to be used.
In order to configure the connection before it is dispensed, the application should register the callback to the ConnectionOpen
event before Open()
is called.
Only supported for .NET Framework 4.x and .NET (Core).
Application Continuity Scenarios
For applications that set state only at the beginning of a request or for stateful applications that gain performance benefits from using connections with a preset state, they can register for a ConnectionOpen
event and then check the reason for the event before taking appropriate action.
When registered, the event will be executed upon successful reconnection following a recoverable error. The triggering event reason will be available through ConnectionOpenReason
property of OracleConnectionOpenEventArgs
object provided with the event.
The application is responsible for ensuring the initialization actions are the same as that of the original connection before failover. If the event invocation fails, then replay is disabled on that connection.
Example
// C#
// NOTE: The sample below requires CPVersion=2.0 to be configured in the .NET configuration
using System;
using Oracle.ManagedDataAccess.Client;
class ConOpenEventSample
{
public static void ConOpenCallback(OracleConnectionOpenEventArgs eventArgs)
{
OracleCommand cmd = new OracleCommand("ALTER SESSION SET NLS_LANGUAGE='GERMAN'", eventArgs.Connection);
cmd.ExecuteNonQuery();
cmd.Dispose();
}
static void Main(string[] args)
{
// Establish a connection
string constr = "user id=hr;password=hr;data source=oracle";
OracleConnection con = new OracleConnection(constr);
con.ConnectionOpen += ConOpenCallback;
con.Open();
con.Dispose();
}
}