Connecting to a Jaguar server
Using the Connection object
The simplest way to connect to a Jaguar server is to use the
capabilities of the Connection object, a
nonvisual object that handles communications with the server. Connecting
to a Jaguar server by using the Connection object is very similar
to connecting to a distributed PowerBuilder server application.
You can write all the code to connect to the Jaguar server
by hand, or you can use the Connection Object wizard to get started.
The remainder of this section describes how to connect to
a Jaguar server by using the Connection object.
Writing the code by hand
Declaring the connection variable
The Connection object is not a built-in global object. You
need to declare a variable of type connection. Typically, you will
want this to be a global or instance variable.
Establishing a connection
To
establish a connection to the Jaguar server, you need to execute
the PowerScript statements required to perform these operations:
- Use the Create statement
to instantiate the Connection object. - Set properties for the Connection object.
- Invoke the ConnectToServer function to establish
a connection to the Jaguar server. - Check for errors.
You can perform these operations in a single script or in
several scripts, but they must be performed in the order shown.
Example The following script instantiates the myconnect Connection
object and sets the connection properties to identify the communications
driver for Jaguar, the host name and port number of the Jaguar server,
and the default package. Then the script invokes the ConnectToServer
function to establish a connection to the server and checks for
errors:
1 |
// Global variable: |
1 |
// connection myconnect |
1 |
long ll_rc |
1 |
myconnect = create connection |
1 |
myconnect.driver = "jaguar" |
1 |
myconnect.location = "Jagserver1:9000" |
1 |
myconnect.application = "PB_pkg_1" |
1 |
myconnect.userID = "bjones" |
1 |
myconnect.password = "mypass" |
1 |
ll_rc = myconnect.ConnectToServer() |
1 |
IF ll_rc <> 0 THEN |
1 |
MessageBox("Connection failed", ll_rc) |
1 |
END IF |
Setting the Connection object properties
The property values you need to specify for the Connection
object are different when you’re connecting to Jaguar from
when you’re connecting to a distributed PowerBuilder server.
Here are some guidelines for setting Connection object properties
when you’re communicating with Jaguar:
Property name | Description | Examples | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Application | The default package to be used for Jaguar components |
“PB_pkg_1” | ||||||||
ConnectString | Not used in Jaguar | |||||||||
Driver | The name of the Jaguar driver | “Jaguar” | ||||||||
Location | The host name and port number for the Jaguar server separated by a colonThe Location property can also specify a fully qualified URL that uses one of the following formats:
To take advantage of Jaguar’s load balancing and failover support, you can also specify a semicolon-separated list of server locations |
“Jagserver:9000″”iiop://srv1:9000″”iiops://srv3:9000″”http://srv5:1080″”iiop://s1:9000;iiop://s2:9000” | ||||||||
Password | The Jaguar password | “mypass” | ||||||||
UserID | The Jaguar user ID | “bjones” | ||||||||
Options | One or more Jaguar ORB property settings | “ORBLogFile=’jaglog.log'” |
Establishing multiple connections
PowerBuilder allows you to instantiate multiple Connection
objects. This makes it possible for you to establish multiple connections
in a single client application. For example, you could instantiate
two separate Connection objects to connect a client to two different
Jaguar servers.
Using the wizard to createa Connection object
When you select Jaguar as the connection type in the Connection
Object wizard, PowerBuilder creates a standard class user object
inherited from the Connection object. You supply the Connection
object properties in the wizard and specify whether connection information
will be provided in the registry, an INI file, or a script.
The Constructor event of the Connection object calls a function, of_getconnectioninfo,
that gets the stored connection information from the source you
specified.
Once you’ve used the Connection Object wizard to
create a Connection object, you need to execute the PowerScript
statements required to perform these operations:
- Use the Create statement
to instantiate the Connection object. - Invoke the ConnectToServer function to establish
a connection to the Jaguar server. - (Optional) Check for errors.
You don’t need to set properties for the Connection
object.
Example The following script instantiates the myconnect instance of
the n_myclient_connect object created by the wizard,
invokes the ConnectToServer function to establish a connection to
the server, and checks for errors:
1 |
long ll_rc |
1 |
myconnect = create n_myclient_connect |
1 |
ll_rc = myconnect.ConnectToServer() |
1 |
IF ll_rc <> 0 THEN |
1 |
MessageBox("Connection failed", ll_rc) |
1 |
END IF |
Establishing multiple connections
You can establish multiple connections in a single client
application. If you want to connect a client to two different Jaguar
servers, run the Connection Object wizard again to create a new
user object with different connection properties.