ConnectToServer PowerScript function
Description
Connects a client application to a server component. The client
application must call ConnectToServer before
it can use a remote object on the server.
This function applies to distributed applications only.
Controls
Connection objects
Syntax
|
1 |
<span>connection</span>.<span>ConnectToServer</span> ( ) |
|
Argument |
Description |
|---|---|
|
connection |
The name of the Connection object you |
Return Values
Long. Returns 0 if it succeeds and one of the following values
if an error occurs:
-
50 Distributed
service error -
52 Distributed communications error
-
53 Requested server not active
-
54 Server not accepting requests
-
55 Request terminated abnormally
-
56 Response to request incomplete
-
57 Connection object not connected to server
-
62 Server busy
-
92 Required property is missing or invalid
Usage
Before calling ConnectToServer, you assign
values to the properties of the Connection object.
Examples
In this example, the client application connects
to a server application using the Connection object myconnect:
|
1 |
// Global variable: |
|
1 |
// connection myconnect |
|
1 |
long ll_rc |
|
1 |
myconnect = create connection |
|
1 |
myconnect.driver = "jaguar" |
|
1 |
myconnect.location = "Jagserver1:2000" |
|
1 |
myconnect.application = "PB_pkg_1" |
|
1 |
myconnect.userID = "bjones" |
|
1 |
myconnect.password = "mypass" |
|
1 |
ll_rc = myconnect.ConnectToServer() |
|
1 |
IF ll_rc <> 0 THEN |
|
1 |
 MessageBox("Connection failed", ll_rc) |
|
1 |
END IF |
You can enclose the ConnectToServer function
in a try-catch block to catch exceptions thrown during the attempt
to connect. This example uses SSLServiceProvider and SSLCallBack
objects to create a secure connection. An exception or other error
in any of the SSLCallback functions raises the CTSSecurity::UserAbortedException.
The error-handling code shown in the example displays a message
box with the text of the error message, but your code should take
additional appropriate action:
|
1 |
SSLServiceProvider   sp<br>// set QOP<br>getcontextservice( "SSLServiceProvider", sp )<br>sp.setglobalproperty( "QOP", "sybpks_simple" )<br>// set PB callback handler<br>sp.setglobalproperty( "CallbackImpl", &<br>   "uo_sslcallback_handler" )<br> <br>// connect to the server<br>connection cxn<br>cxn.userid = "jagadmin"<br>cxn.password = "sybase"<br>cxn.driver = "jaguar"<br>cxn.application = "dbgpkg"<br>cxn.options = "ORBLogFile='d:PBJagClient.Log'"<br>cxn.location = "iiops://localhost:9001"<br> |
|
1 |
TRY<br>   l_rc = cxn.ConnectToServer()<br>CATCH (userabortedexception uae)<br>   MessageBox("UserAbortedException Caught", &<br>      "ConnectToServer caught: " + uae.getMessage() )<br>   l_rc = 999<br>CATCH ( CORBASystemException cse )<br>   MessageBox("CORBASystemException Caught", &<br>      "ConnectToServer caught: " + cse.getMessage() )<br>   l_rc = 998<br>CATCH ( RuntimeError re )<br>   MessageBox("RuntimeError Exception Caught", &<br>      "ConnectToServer caught: " + re.getMessage() )<br>   l_rc = 997<br>CATCH ( Exception ex )<br>   MessageBox("Exception Caught", &<br>      "ConnectToServer caught: " + ex.getMessage() )<br>   l_rc = 996<br>END TRY |
|
1 |
<br> |
|
1 |
IF l_rc <> 0 THEN<br>   MessageBox("Error", "Connection Failed - code: " &<br>      + string(l_rc) )<br>   MessageBox("Error Info", "ErrorCode= " + &<br>      string(cxn.ErrCode) + "~nErrText= " + &<br>   cxn.ErrText)<br>ELSE<br>   MessageBox("OK", "Connection Established")<br>END IF |