Using Persistent Connections

To establish a persistent connection, set the COMTIContext keyword CONNTYPE to OPEN. If a call with CONNTYPE set to OPEN completes successfully, the returned COMTIContext array CONNTYPE keyword has a value of USE.

To make a call and terminate the persistent connection, set the CONNTYPE keyword to CLOSE. If a call with CONNTYPE set to CLOSE completes successfully, the returned COMTIContext array CONNTYPE keyword has a value of NON-PERSISTENT.

After you set the COMTIContext keyword CONNTYPE to OPEN, CONNTYPE can be set to USE. However, this action is not mandatory because it is set to USE by default.

All TI objects include the intrinsic methods ClosePersistentConnect and UpdateContextInfo for use when dealing with persistent connections.

If the method call fails, the COMTIContext array cannot be updated and the client should call the intrinsic method UpdateContextInfo and then the GetConnectionInfo method on the COMTIContextLib.ContextObject to obtain updated status of the connection.

You can call ClosePersistentConnection at any time to close a persistent connection. The connection will be terminated and there will be no interaction with a server program.

The following Visual Basic 6.0 code sample shows how to use the OPEN and CLOSE method calls that might return an error. The sample also demonstrates how to determine whether a connection can still be used.

Public CtxCount As Long
Public COMTIContext() As Variant
Public ContextObj As COMTIContextLib.ContextObject

Dim fConIsPersistent as Boolean
Dim fConnIsViable as Boolean
Dim varConnType as Variant

Private Sub cmdBalance_Click(fCloseWIthMethod As Boolean)
  On Error GoTo ErrorHandler

OpenCall:
  varConnType = "OPEN"
  ContextObj.WriteContext "CONNTYPE", varConnType, COMTIContext
  lngReturn = objBank.cedrbank(txtName.Text, txtAccount.Text, curRetBalance, COMTIContext)

UseCall:
  lngReturn = objBank.cedrbank(txtName.Text, txtAccount.Text, curRetBalance, COMTIContext)

CloseCall:
  If (fCloseWithMethod) Then
      varConnType = "CLOSE"
      ContextObj.WriteContext "CONNTYPE", varConnType, COMTIContext
      lngReturn = objBank.cedrbank(txtName.Text, txtAccount.Text, curRetBalance, COMTIContext)
  Else
      COMTIContext = objBank.ClosePersistentConnection
  End-if

  Exit Sub

ErrorHandler:
    COMTIContext  = objBank.UpdateContextInfo  ‘ Optional for COM required for .NET
    ContextObj.GetConnectionInfo (COMTIContext, fConnIsPersistent, fConnIsViable)
    If (fConnIsPersistent = True And fConnIsViable = True) Then
        ‘Continue with the next Use or Close method call is OK
    Else
        ‘Connection is either Non-persistent or no longer viable
        ‘So a Use or Close call is not valid
    End-if
    Exit Sub

End Sub

To download updated Host Integration Server 2004 Help from www.microsoft.com, go to http://go.microsoft.com/fwlink/?linkid=29507.

Copyright © 2004 Microsoft Corporation.
All rights reserved.
Show: