Connecting to a server – PB Docs 70

Connecting to a server

To allow a client application
to function in a distributed environment, you need to connect to
a server application. Connecting to a server application is very similar
to connecting to a database. To establish the connection, you use
the Connection object, a nonvisual object
that works like the Transaction object.

note.gif Version 5 clients cannot connect to Version 6 or 7
Because of architectural changes made in PowerBuilder Version
6, client applications written in Version 5 cannot connect to server
applications written in Version 6 or 7.

Declaring the connection variable

the Transaction object, 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

establish a connection to a server application, you need to execute
the PowerScript statements required to perform these operations:

  1. Use the Create statement
    to instantiate the Connection object.
  2. Set properties for the Connection object.
  3. Invoke the ConnectToServer function to establish
    a connection to the server application.
  4. (Optional) 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 above.

Example The following script instantiates the myconnect Connection
object and sets the connection properties to identify the communications
driver, the server location, and the name of the server application.
Then the script invokes the ConnectToServer function to establish
a connection to the server and checks for errors. This example uses
the WinSock driver:

WinSock name resolution

To tell PowerBuilder how to connect to the server application,
you specify values for the Location and Application properties of
the Connection object. When you use the WinSock driver, you can
specify the IP address and port number for the server directly,
or provide a service name and a host name. If you specify a service
name and/or host name, PowerBuilder uses your TCP/IP network
settings to locate the server application. To determine the IP address and
port number for the server, PowerBuilder will use standard name resolution
procedures such as DNS, WINS, and the hosts and services files.

Updating the hosts and services files

If you use the hosts and services files for name resolution,
you need to be sure to use the correct format for the entries you
add. For example, to identify the dpbserv service, you could include
an entry like the following in the services file:

note.gif Line must be terminated with a carriage return or linefeed If you add an entry to the end of the services file, you need
to press return after the final entry. Otherwise,
the final entry will not be recognized.

To identify the server01 host, you could include an entry
like the following in the hosts file:

The location of the services and hosts files depends on which
TCP/IP implementation and operating system you use.

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
server applications. The connections could be established by using
the same or different communications drivers.

Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x