Skip Headers
Oracle® Objects for OLE Developer's Guide
11g Release 2 (11.2) for Microsoft Windows

Part Number E17727-03
Go to Documentation Home
Go to Book List
Book List
Go to Table of Contents
Go to Index
Go to Feedback page
Contact Us

Go to previous page
Go to next page
PDF · Mobi · ePub

ConnectSession Method

Applies To

OraSession Object


Returns the OraSession object with the specified name that is associated with the OraClient object of the specified session.


Set orasession2 = orasession1.ConnectSession(session_name)


The arguments for the method are:

Arguments Description
session_name A String specifying the name of the session.


This method is provided for simplicity and is equivalent to iterating through the OraSessions collection of the OraClient object of the current session and searching for a session named session_name. The OraSessions collection contains only sessions created through the current application. This means that it is not possible to share sessions across applications, only within applications.


This example demonstrates the use of the ConnectSession and CreateNamedSession methods to allow an application to use a session it previously created, but did not save. Copy this code into the definition section of a form. Then, press F5.

Sub Form_Load ()
 'Declare variables
 Dim dfltsess As OraSession
 Dim OraSession As OraSession 
 'Create the default OraSession Object.
 Set dfltsess = CreateObject("OracleInProcServer.XOraSession")
 'Try to connect to "ExampleSession". If it does not exist 
 'an error is generated.
 On Error GoTo SetName
 Set OraSession = dfltsess.ConnectSession("ExampleSession")
 On Error GoTo 0
 'You can specify other processing here, such as creating a
 ' database and/or dynaset.
Exit Sub
'The session named "ExampleSession" was not found, so create it.
Set OraSession = dfltsess.Client.CreateSession("ExampleSession")
Resume Next
End Sub