Try OpenEdge Now
skip to main content
.NET Open Clients
Connecting to an AppServer : Establishing the connection : Returning a user defined string to the client from the AppServer connection procedure
 

Returning a user defined string to the client from the AppServer connection procedure

When you establish a connection to the AppServer with the .NET Open Client, you instantiate an AppObject using one of the four constructors provided by ProxyGen. If the connection to the AppServer fails, the AppObject constructor throws a standard exception. This exception can also contain a user defined string, if you set up your AppServer to do so.
The Connection object communicates with a remote ABL procedure stored on the AppServer known as the connection procedure. If that procedure contains the ABL RETURNstring statement, then that string will be contained in the connection failure exception.
If the connection is successful, and the connection procedure has a RETURNstring statement, you can access the string using the existing AppObject public property ProcReturnString. If the connect procedure does not return a value, then the ProcReturnString property will be null.
The following sample .NET Open Client code illustrates this functionality:

try
{
   //Create Customer AppObject to connect
   Customer appObj = new Customer(ConnectObj);

   MessageBox.Show(appObj.ProcReturnString);
}
catch (Progress.Open4GL.Exceptions.Open4GLException ex)
{
   // if there is a application defined return string, then display it
   if (ex.ProcReturnString != string.Empty)
   {
      MessageBox.Show(ex.ProcReturnString);
   }
   else
   {
      // display Progress defined error message
      MessageBox.Show(ex.ToString());

      // or display new generic message
      MessageBox.Show("Connection failed");
  }
}
finally
{
   if (appObj != null)
   {
      appObj.Dispose();
   }
}
If the connection is successful and the connect procedure returns a string, then the string value is displayed by the first message box. If the connect procedure failed and returns a string, then the string value is displayed by the second message box.
Note: This feature is only available to AppServer applications using the managed-session model, since it is this type of application that uses a connection procedure.