Creating a Connection object

When you select Application Server as the connection type in the Connection Object wizard, PowerBuilder creates a standard class user object that inherits from the Connection object. You supply the connection-object properties in the wizard and specify whether connection information will be in the registry, an INI file, or a script. The Connection Object wizard gets information about the server to which you want to connect from the application server profiles. See “Creating an application server profile”.

The Constructor event of the new Connection object calls the function of_getconnectioninfo, which gets the stored connection information from the source you specified.

Once you have completed the Connection Object wizard, execute these PowerScript statements:

  1. Use the Create statement to instantiate the connection object.

  2. Invoke the ConnectToServer function to establish a connection to the server.

  3. Check for errors.

You need not 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.

Example The following script instantiates the myconnect instance of the n_myclient_connect object that is created by the wizard, invokes the ConnectToServer function to establish a connection to the server, and checks for errors:

long ll_rc
myconnect = create n_myclient_connect
ll_rc = myconnect.ConnectToServer()
IF ll_rc <> 0 THEN
	MessageBox("Connection failed", ll_rc)
END IF

Establishing multiple connections

You can establish multiple connections in a single client application. To connect a client to two different servers, run the Connection Object wizard again to create a new user object with different connection properties.