Connecting to EAServer
Using the Connection object
The simplest way to connect to EAServer is
to use the capabilities of the Connection object,
a nonvisual object that handles communications with the server.
You can write all the code to connect to the server by hand, or
you can use the Connection Object wizard to get started.
Writing the code by hand
Declaring the connection variable
The Connection object is not a built-in global object. You
need to declare a global or instance variable of type connection.
Establishing a connection
To establish
a connection to the 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 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 EAServer, the host
name and port number of the 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:<br />// connection myconnect<br />long ll_rc<br />myconnect = create connection<br />myconnect.driver = "jaguar"<br />myconnect.location = "Jagserver1:9000"<br />myconnect.application = "PB_pkg_1"<br />myconnect.userID = "bjones"<br />myconnect.password = "mypass"<br />ll_rc = myconnect.ConnectToServer()<br />IF ll_rc <> 0 THEN<br /> MessageBox("Connection failed", ll_rc)<br />END IF |
Setting the Connection object properties
Table 25-1 provides
some guidelines for setting Connection object properties when you
are communicating with EAServer.
Property name | Description | Examples | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Application | The default package to be used for EAServer components | “PB_pkg_1” | ||||||||
Driver | The name of the EAServer driver. | “jaguar” | ||||||||
Location | The host name and port number for the server, separated by a colon. The Location property can also specify a fully qualified URL
To take advantage of EAServer’s load |
“Jagserver:9000”
“iiop://srv1:9000” “iiops://srv3:9001” “http://srv5:1080” “iiop://s1:9000;iiop://s2:9000” |
||||||||
Password | The EAServer password. | “mypass” | ||||||||
UserID | The EAServer user ID. |
“bjones” | ||||||||
Options | One or more EAServer 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
servers.
Setting options
When you connect to EAServer using
either the Connection object or the JaguarORB object, you are using
the EAServer C++ client
ORB. You can set its properties in the Options string of the Connection
object or using JaguarORB’s Init function.
Using a different code set
To connect to an EAServer component that handles
double-byte characters, make sure the component is using the correct
code set. The code set can be changed in the Component Properties
dialog box in EAServer Manager. You must also set your PowerBuilder
client’s code set to use the component. To do so, set the
Options property of the Connection object. For example, if you want to
handle Korean characters in the eucksc code set, use the following
script for a Connection object called myConnection:
1 |
myConnection.Options = "ORBCodeSet='eucksc'" |
If EAServer was started using the utf-8 codeset
and you are calling a Java or PowerBuilder component that returns
a string containing the Euro and/or British pound symbol,
set the ORBCodeSet property to cp1252. For example:
1 |
myConnection.Options = "ORBCodeSet='cp1252'" |
Troubleshooting connections
When a connection fails, you can obtain more information about
the failure in a log file by enabling the ORBLogIIOP option and
specifying a value for the ORBLogFile option. If you want to set
multiple options, they must be set in the same statement. Separate
the options with commas:
1 |
myConnection.Options = &<br /> "ORBLogIIOP='TRUE', ORBLogFile='d: empORBLog.txt'" |
For a complete list of options, see the online Help for the
Connection object or the EAServer documentation.
Using the wizard to create a Connection object
When you select EAServer 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 Connection Object
wizard gets information about the server you want to connect to
from the EAServer profiles you
have set up. For how
to create an EAServer profile,
see “Creating an EAServer profile “.
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 have 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 server. - (Optional) Check for errors.
You do not need to set properties for the Connection object,
but you can modify them in the of_getconnectioninfo function.
You can also set options for the Connection object in its constructor
event, for example:
1 |
this.options = "ORBHttp='TRUE'" |
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<br />myconnect = create n_myclient_connect<br />ll_rc = myconnect.ConnectToServer()<br />IF ll_rc <> 0 THEN<br /> MessageBox("Connection failed", ll_rc)<br />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 servers,
run the Connection Object wizard again to create a new user object
with different connection properties.