ct_connect

Description

Connects to a server.

Syntax

CS_RETCODE ct_connect(connection, servername,
                       servername_len); 
CS_CONNECTION   *connection;
CS_CHAR         *servername;
CS_INT          servername_len

Parameters

connection

(I) Handle for this SNA connection. This connection handle must be allocated with ct_con_alloc. The connection handle corresponds to the TDPROC handle in the Open ServerConnect Gateway-Library.

servername

(I) Name of the connected server. For clients running SNA, this is the name by which the server is known to the Open ClientConnect Server Path Definition Table. For clients running TCP/IP without a gateway, this is the actual name of the Adaptive Server Enterprise in the LAN interfaces file.

You must assign a value to this argument. If a server name is not specified, ct_connect fails.

servername_len

(I) Length, in bytes, of servername.

Returns

ct_connect returns one of the following values:

Value

Meaning

CS_SUCCEED (-1)

The routine completed successfully.

CS_FAIL (-2)

The routine failed.

TDS-CRTABLE-UNAVAILABLE (-31)

The connection router table cannot be loaded.

Examples

Example 1

The following code fragment demonstrates the use of ct_connect. It is taken from the sample program SYCTSAA6 in Appendix A, “Sample Language Application.”

	/********************************************************************/
	/*                                                                  */
	/* Subroutine to process input data                                 */
	/*                                                                  */
	/********************************************************************/
		void   proces_input ()
	{
 	CS_INT        rc;
	CS_INT        *outlen;
	CS_INT        buf_len;
	CS_INT        msglimit;
	CS_INT        netdriver;
	/*------------------------------------------------------------*/
	/* Allocate a connection to the server                        */
	/*------------------------------------------------------------*/
	rc = ct_con_alloc (context, &connection);

         if (rc != CS_SUCCEED)
         {
            strncpy (msgstr, "CT_CONALLOC failed", msg_size);
            no_errors_sw = FALSE ;
            error_out (rc);
          }
  	/*------------------------------------------------------------*/
  	/* Alter properties of the connection for user-id             */
  	/*------------------------------------------------------------*/
  
         buf_len  = user_size;
         rc = ct_con_props (connection, (long)CS_SET,
                            (long)CS_USERNAME, username,
                            buf_len, outlen);
  
         if (rc != CS_SUCCEED)
         {
            strncpy (msgstr, "CT_CON_PROPS for user-id failed",
            msg_size);
            no_errors_sw = FALSE ;
            error_out (rc);
          }
  	/*------------------------------------------------------------*/
  	/* Alter properties of the connection for password            */
  	/*------------------------------------------------------------*/
  
         buf_len = pwd_size;
         rc = ct_con_props (connection, (long)CS_SET,
                           (long)CS_PASSWORD, pwd, buf_len, outlen);
  
          if (rc != CS_SUCCEED)
          {
            strncpy (msgstr, "CT_CON_PROPS for password failed",
            msg_size);
            no_errors_sw = FALSE ;
            error_out (rc);
          }
  
  	/*------------------------------------------------------------*/
  	/* Alter properties of the connection for transaction         */
  	/*------------------------------------------------------------*/
  
         buf_len = tran_size;
         rc = ct_con_props (connection, (long)CS_SET,
                           (long)CS_TRANSACTION_NAME,
                           tran, buf_len, outlen);
  
         if (rc != CS_SUCCEED)
         {
            strncpy (msgstr, "CT_CON_PROPS for transaction failed",
            msg_size);
            no_errors_sw = FALSE ;
            error_out (rc);
         }
  	/*------------------------------------------------------------*/
  	/* Alter properties of the connection for network driver      */
  	/*------------------------------------------------------------*/
  
         netdriver = 9999;   /* default value for non-regconized
                                driver name                     */
  
         /* if no netdriver entered, default is LU62  */
         if (strncmp(driver,"         ",9) == 0  ??
             strncmp(driver,"LU62",4) == 0)
            netdriver = CS_LU62;
  
         else if (strncmp(driver,"INTERLINK",8) == 0)
            netdriver = CS_INTERLINK;
  
         else if (strncmp(driver,"IBMTCPIP",8) == 0)
            netdriver = CS_TCPIP;
  
         else if (strncmp(driver,"CPIC",4) == 0)
            netdriver = CS_NCPIC;
  
         rc = ct_con_props (connection, (long)CS_SET,
                           (long)CS_NET_DRIVER, (long) netdriver,
                           CS_UNUSED, outlen);
  
         if (rc != CS_SUCCEED)
         {
            strncpy (msgstr, "CT_CON_PROPS for network driver failed",
            msg_size);
            no_errors_sw = FALSE ;
            error_out (rc);
         }
  	/*------------------------------------------------------------*/
  	/* Setup retrieval of All Messages                            */
  	/*------------------------------------------------------------*/
  
         rc = ct_diag (connection, CS_INIT,
                       CS_UNUSED, CS_UNUSED, CS_NULL);
  
         if (rc != CS_SUCCEED)
         {
            strncpy (msgstr, "CT_DIAG CS_INIT failed", msg_size);
            no_errors_sw = FALSE ;
            error_out (rc);
         }
  	/*------------------------------------------------------------*/
  	/* Set the upper limit of number of messages                  */
  	/*------------------------------------------------------------*/
  	      msglimit = 5 ;
  
         rc = ct_diag (connection, CS_MSGLIMIT, CS_ALLMSG_TYPE,
                       CS_UNUSED, &msglimit);
  
         if (rc != CS_SUCCEED)
         {
            strncpy (msgstr, "CT_DIAG CS_MSGLIMIT failed", msg_size);
            no_errors_sw = FALSE ;
            error_out (rc);
         }
  	/*------------------------------------------------------------*/
  	/* Open connection to the server or CICS region               */
  	/*------------------------------------------------------------*/
         rc = ct_connect (connection, servname, server_size);
  
         if (rc != CS_SUCCEED)
         {
            strncpy (msgstr, "CT_CONNECT failed", msg_size);
            no_errors_sw = FALSE ;
            error_out (rc);
         }
  	/*------------------------------------------------------------*/
  	/* Invokes SEND_COMMAND routine                               */
  	/*------------------------------------------------------------*/
         if (no_errors_sw)
            send_command ();

Usage

See also

Related functions

Related topics

Related documentation