ct_connect

Description

Connect to a server.

Syntax

CS_RETCODE ct_connect(connection, server_name,
                  snamelen)
 
 CS_CONNECTION    *connection;
 CS_CHAR                  *server_name;
 CS_INT                       snamelen;

Parameters

connection

A pointer to a CS_CONNECTION structure. A CS_CONNECTION structure contains information about a particular client/server connection.

Use ct_con_alloc to allocate a CS_CONNECTION structure, and ct_con_props to initialize that structure with login parameters.

server_name

A pointer to the name of the server to connect to. *server_name is the name of the server’s entry in the connection’s directory source. ct_connect looks up *server_name in the connection’s directory source to determine how to connect to that server. A connection’s directory source is specified with the CS_DS_PROVIDER property. See “Directory service provider”. This can be either the Sybase interfaces file or a network-based directory service.

server_name must use the naming syntax recognized by the connection’s directory provider. Most network-based directory providers allow a base directory path (DIT base) to be specified with the CS_DS_DITBASE connection property. If server_name is a partially qualified name, the directory provider combines it with the DIT base to form a fully qualified name.

If server_name is NULL, ct_connect uses a platform-specific default for the server name. On platforms that support environment variables or logical names, this is the value of the DSQUERY environment variable or logical name. On these platforms, if DSQUERY has not been set, ct_connect looks for a server with the name SYBASE.

snamelen

The length, in bytes, of *server_name. If *server_name is null-terminated, pass snamelen as CS_NULLTERM. If server_name is NULL, pass snamelen as 0 or CS_UNUSED.

Returns

ct_connect returns the following values:

Return value

Meaning

CS_SUCCEED

The routine completed successfully.

CS_FAIL

The routine failed.

CS_PENDING

Asynchronous network I/O is in effect. See “Asynchronous programming”.

CS_BUSY

An asynchronous operation is already pending for this connection. See “Asynchronous programming”.

Common reason for a ct_connect failure include:

Examples

Example 1

      /* ex_connect() */
       CS_RETCODE CS_PUBLIC
       ex_connect(context, connection, appname,username, password,
             server)
         CS_CONTEXT       context;
         CS_CONNECTION  *connection;
         CS_CHAR      *appname;
         CS_CHAR      *username;
         CS_CHAR      *password;
         CS_CHAR      *server;
         {
             CS_INT        len;
             CS_RETCODE    retcode;
            /* Allocate a connection structure */
             ...CODE DELETED.....
            /* Set properties for new connection */
             ...CODE DELETED.....
            /* Open the connection */
             if (retcode == CS_SUCCEED)
             {
                 len = (server == NULL) ? 0 : CS_NULLTERM;
                 retcode = ct_connect(*connection, server, len);
                 if (retcode != CS_SUCCEED)
                 {
                     ex_error("ct_connect failed");
                 }
             }
            if (retcode != CS_SUCCEED)
             {
                 ct_con_drop(*connection);
                 *connection = NULL;
             }
            return retcode;
         }

This code excerpt is from the exutils.c sample program.

Usage


Server address information


Configuring connection defaults externally

See also

ct_close, ct_con_alloc, ct_con_drop, ct_con_props, ct_remote_pwd, “Directory services”, “Interfaces file”, “Properties”, “Server directory object”