Skip Headers

Oracle® Objects for OLE Developer's Guide
10g Release 1 (10.1)

Part Number B10118-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Master Index
Master Index
Go to Feedback page
Feedback

CreateNamedSession Method Example

This example demonstrates the use of ConnectSession and CreateNamedSession 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

Dim OraDatabase As OraDatabase

Dim OraDynaset As OraDynaset

'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

'Create the OraDatabase Object by opening a connection to Oracle.

Set OraDatabase = OraSession.OpenDatabase("ExampleDb", "scott/tiger", 0&)

'Create the OraDynaset Object.

Set OraDynaset = OraDatabase.CreateDynaset("select * from emp", 0&)

'Display or manipulate data here

Exit Sub

SetName:

'The session named "ExampleSession" was not found, so create it.

Set OraSession = dfltsess.CreateNamedSession("ExampleSession")

Resume Next

End Sub