Attach Method for an Application

The Attach method allows an external application to reconnect to an existing Siebel session. It returns a Boolean value that indicates if Siebel CRM successfully ran the method.

Format

Application.Attach(sessionString)

The following table describes the arguments for the Attach method.

Argument Description

sessionString

A string that contains the Siebel Session Id. This argument is typically the output of the Detach method.

Used With

COM Data Control, Siebel Java Data Bean

Examples

The examples in this topic do the following work:

  1. Start an instance of COM Data Control.

  2. Log in to a Siebel Server.

  3. Detach the instance.

  4. Determine the session string.

  5. Start another instance of COM Data Control.

    The script does not log in again. Instead, it uses the session string to access the existing session. This technique reuses the connection that the first instance created.

The following example uses 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 uses the Siebel 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 Java Data Bean
         m_dataBean_first = new SiebelDataBean();

         // Login to the Siebel 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 Siebel 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());
      }
   }
}