SAS 9.1.3 Integration Technologies » Developer's Guide


Developing Windows Clients
Client Requirements
Client Installation
Security
Selecting a Windows Programming Language
Programming with Visual Basic
Programming in the .NET Environment
Using VBScript
Programming with Visual C++
Using the Object Manager
Creating an Object
Object Manager Interfaces
Using a Metadata Server with the Object Manager
Metadata Configuration Files
Error Reporting
Code Samples
Using Connection Pooling
Choosing Integration Technologies or COM+ Pooling
Using Integration Technologies Pooling
Using Com+ Pooling
Pooling Samples
Using the IOM Data Provider
Using the Workspace Manager
Class Documentation
Windows Clients

SAS Object Manager Code Samples

Using CreateObjectByServer to Make a Connection

Samples 1 through 5 show how to create a connection by specifying server parameters (machine, protocol, port) directly in the source code.

Samples 1, 2, and 3 show synchronous connections. The synchronous connection is the most frequently used and is the simplest connection to create. The advantage of making an asynchronous connection is that the client application can continue executing code while the connection is being established. The application could start several connections at the same time, then wait for all of them to complete. This could be useful for applications that need to run multiple SAS servers at the same time.

Samples 4 and 5 use asynchronous connections. When making asynchronous connections, the ObjectKeeper maintains a reference to the created object until you call ObjectKeeper.RemoveObject; this call is not shown in the sample 4 and 5 example code.

The ObjectFactory adds the newly created object to the ObjectKeeper as soon as the connection is established. You can then use the ObjectKeeper to get the connection.

Sample 1. Make a connection to a local workspace using COM:

   Dim obObjectFactory As New SASObjectManager.ObjectFactory
   Dim obSAS As SAS.Workspace
 
   Set obSAS = obObjectFactory.CreateObjectByServer(
      "myName", True, Nothing, "", "")

Sample 2. Make a connection to a remote workspace using DCOM:

   Dim obObjectFactory As New SASObjectManager.ObjectFactory
   Dim obSAS As SAS.Workspace
   Dim obServer As New SASObjectManager.ServerDef
 
   obServer.MachineDNSName = "RemoteMachine.company.com"
 
   Set obSAS = obObjectFactory.CreateObjectByServer(
      "myName", True, obServer, "", "")

Sample 3. Make a connection to a remote workspace using IOM Bridge:

   Dim obObjectFactory As New SASObjectManager.ObjectFactory
   Dim obSAS As SAS.Workspace
   Dim obServer As New SASObjectManager.ServerDef
 
   obServer.MachineDNSName = "RemoteMachine.company.com"
   obServer.Protocol = ProtocolBridge
   obServer.Port = 6903
 
   Set obSAS = obObjectFactory.CreateObjectByServer("myName", True, obServer, 
      "myUserName", "myPassword")

Sample 4. Start multiple connections asynchronously

   Dim obObjectFactory As New SASObjectManager.ObjectFactory
   Dim obObjectKeeper As New SASObjectManager.ObjectKeeper
   Dim obSAS As SAS.Workspace
   Dim obSAS2 As SAS.Workspace
   Dim obServer As New SASObjectManager.ServerDef
   Dim obServer2 As New SASObjectManager.ServerDef
 
   obServer.MachineDNSName = "MachineA.company.com"
   obServer.Protocol = ProtocolBridge
   obServer.Port = 6903
   obObjectFactory.CreateObjectByServer "myName", False, obServer,
      "myUsername", "myPassword"
 
   obServer2.MachineDNSName = "MachineB.company.com"
   obServer2.Protocol = ProtocolBridge
   obServer2.Port = 6903
   obObjectFactory.CreateObjectByServer "myName2", False, obServer2,
      "myUsername", "myPassword"
 
   ' Note that the first parameter here matches the first parameter in the
   ' call to CreateObjectByServer
   Set obSAS = obObjectKeeper.WaitForObject("myName", 10000)
   Set obSAS2 = obObjectKeeper.WaitForObject("myName2", 10000)

Sample 5. Listen for events using asynchronous connections

   Public WithEvents obObjectKeeperEvents As SASObjectManager.ObjectKeeper
 
   Private Sub Form_Load()
   Dim obObjectFactory As New SASObjectManager.ObjectFactory
   Dim obObjectKeeper As New SASObjectManager.ObjectKeeper
   Dim obSAS As SAS.Workspace
   Dim obSAS2 As SAS.Workspace
   Dim obServer As New SASObjectManager.ServerDef
   Dim obServer2 As New SASObjectManager.ServerDef
 
   Set obObjectKeeperEvents = obObjectKeeper
 
   obServer.MachineDNSName = "MachineA.company.com"
   obServer.Protocol = ProtocolBridge
   obServer.Port = 6903
   obObjectFactory.CreateObjectByServer "myName", False, obServer,
      "myUsername", "myPassword"
 
   obServer2.MachineDNSName = "Machineb.company.com"
   obServer2.Protocol = ProtocolBridge
   obServer2.Port = 6903
   obObjectFactory.CreateObjectByServer "myName2", False, obServer2,
      "myUsername", "myPassword"
 
   End Sub
 
   Private Sub obObjectKeeperEvents_ErrorAdded(ByVal objectName As String,
      ByVal errInfo As String)
   Debug.Print "Error creating " & objectName & ": " & errInfo
   End Sub
 
   Private Sub obObjectKeeperEvents_ObjectAdded(ByVal objectName As String,
      ByVal objectUUID As String)
   Debug.Print "Added object " & objectName & ": " & objectUUID
   Dim obSAS As SAS.Workspace
   Set obSAS = obObjectKeeperEvents.GetObjectByUUID(objectUUID)
   Debug.Print obSAS.UniqueIdentifier
   End Sub

Using CreateObjectByLogicalName to Make a Connection

The CreateObjectByLogicalname method creates a SAS object from a logical name definition. When you use CreateObjectByLogicalname, you must define server metadata for your connections and associate a logical name with the connection. This technique enables you to administratively change the machines where SAS is running without modifying your source code.

The following sample shows how to make a connection to a logical server.

   Dim obObjectFactory As New SASObjectManager.ObjectFactory
   Dim obSAS As SAS.Workspace
   ' This assumes that your metadata configuration files are in the default
   ' location, or that the location of your configuration files is stored
   ' in the registry. If this is not the case, or you want each application
   ' on a given machine to use its own metadata repository, then you should
   ' call
   ' obObjectFactory.SetMetadataFile systemFile, userFile, false
   Set obSAS = obObjectFactory.CreateObjectByLogicalName("myName", True,
      "LogicalName", "LoginReference")