sqlany_connect( a_sqlany_connection *, const char *) method

Creates a connection to a SQL Anywhere database server using the supplied connection object and connection string.

Syntax

public sacapi_bool sqlany_connect ( a_sqlany_connection * sqlany_conn, const char * str)

Parameters

Returns

1 if the connection is established successfully or 0 when the connection fails. Use sqlany_error() to retrieve the error code and message.

Usage

The supplied connection object must first be allocated using sqlany_new_connection().

The following example demonstrates how to retrieve the error code of a failed connection attempt:

                 
a_sqlany_connection * sqlany_conn;
sqlany_conn = sqlany_new_connection();
if( !sqlany_connect( sqlany_conn, "uid=dba;pwd=sql" ) ) {
    char reason[SACAPI_ERROR_SIZE];
    sacapi_i32 code;
    code = sqlany_error( sqlany_conn, reason, sizeof(reason) );
    printf( "Connection failed. Code: %d Reason: %s\n", code, reason );
} else {
    printf( "Connected successfully!\n" );
    sqlany_disconnect( sqlany_conn );
}
sqlany_free_connection( sqlany_conn );

For more information on connecting to a SQL Anywhere database server, see Connection parameters and SQL Anywhere database connections.