The Connection object is not a built-in global object. You need to declare a global or instance variable of type 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:
// Global variable: // connection myconnect long ll_rc myconnect = create connection myconnect.driver = "jaguar" myconnect.location = "Jagserver1:2000" myconnect.application = "PB_pkg_1" myconnect.userID = "bjones" myconnect.password = "mypass" ll_rc = myconnect.ConnectToServer() IF ll_rc <> 0 THEN MessageBox("Connection failed", ll_rc) END IF
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 server, separated by a colon. The Location property can also specify a fully qualified URL that uses one of the following formats: iiop://host:port iiops://host:port http://host:port https://host:port To take advantage of EAServer’s load balancing and failover support, you can also specify a semicolon-separated list of server locations. |
"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 ID. |
"bjones" |
Options |
One or more EAServer ORB property settings. |
"ORBLogFile='jaglog.log'" |
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.