Siebel Object Interfaces Reference > Interfaces Reference > Application Methods >

Attach Method


The Attach method allows an external application to reconnect to an existing Siebel session.

Syntax

Application.Attach(sessionString)

Argument
Description

sessionString

A string containing the Siebel Session Id. The sessionString is typically the output of the Detach method or a value returned from the Siebel cookie.

Returns

Boolean indicating whether or not the method was successfully executed

Used With

COM Data Control, Java Data Bean

Examples

Each of these examples instantiates the first COM Data Control instance, logs in to a Siebel Server, detaches this instance, and then gains the session string. It then instantiates the second COM Data Control instance. It does not need to log in again, as it attaches to the existing session by using the session string. This reuses the connection created by the first instance.

The following example is for COM Data Control and is written in native Visual Basic:

Dim SiebelApplication_first As SiebelDataControl
Dim SiebelApplication_second As SiebelDataControl
Dim errCode As Integer
Dim sessionString As String
Dim attachResult As Boolean
Dim errText As String

' Instantiate the first instance
Set SiebelApplication_first = CreateObject("SiebelDataControl.SiebelDataControl.1")

' Login to Siebel
SiebelApplication_first.Login "host=""Siebel.TCPIP.none.none://<virtual ip>:<port>/<enterprise>/<object manager>""", "<user id>", "<password>"

errCode = SiebelApplication_first.GetLastErrCode
If errCode <> 0 Then
   errText = SiebelApplication_first.GetLastErrText
   MsgBox errText
   Exit Sub
End If

' Detach this instance from Siebel and get session id
sessionString = SiebelApplication_first.Detach
MsgBox "The session string is: " & sessionString

' Instantiate the second instance
Set SiebelApplication_second = CreateObject("SiebelDataControl.SiebelDataControl.1")

' Attach the existing session to this instance
attachResult = SiebelApplication_second.Attach(sessionString)
If (attachResult = True) Then
   MsgBox "Session attached!"
Else
   MsgBox "Session attach failed"
End If

SiebelApplication_second.LogOff
Set SiebelApplication_second = Nothing
Set SiebelApplication_first = Nothing

The following example is for Java Data Bean:

import com.siebel.data.*;
import com.siebel.data.SiebelException;

public class JDBAttachDetachDemo
{
   private SiebelDataBean m_dataBean_first = null;
   private SiebelDataBean m_dataBean_second = null;

   public static void main(String[] args)
   {
      JDBAttachDetachDemo demo = new JDBAttachDetachDemo();
   }

   public JDBAttachDetachDemo()
   {
      try
      {
         // Instantiate the Siebel Data Bean
         m_dataBean_first = new SiebelDataBean();

         // Login to the servers
         m_dataBean_first.login("siebel.TCPIP.none.none://<virtualip>:2320/<enterprise>/<object manager name>","<user id>","<password>");

         System.out.println("Logged in to the Siebel server ");

         //Get the Detach Handle
         String detachHandle = m_dataBean_first.detach();
         System.out.println("The session id is: " + detachHandle);

         // Instantiate another Java Data Bean
         SiebelDataBean m_dataBean_second = new SiebelDataBean();

         // Do Attach
         System.out.println("Attaching in to the Siebel server ");
         m_dataBean_second.attach(detachHandle);
         System.out.println("Attach Done ");

         // Logoff
         m_dataBean_second.logoff();
      }

      catch (SiebelException e)
      {
         System.out.println(e.getErrorMessage());
      }
   }
}

Siebel Object Interfaces Reference