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:2000"<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 24-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 The Location property can also specify a fully qualified URL
To take advantage of EAServer’s load |
“localserver:2000” “iiop://srv1:2000” “iiops://srv3:2001” “http://srv5:8000” “iiop://s1:2000;iiop://s2:2000” |
||||||||
Password |
The EAServer password. |
“mypass” |
||||||||
UserID |
The EAServer user |
“bjones” |
||||||||
Options |
One or more EAServer ORB property |
“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.