Skip to content

SQLAllocConnect

SQLAllocConnect#

SQLAllocConnect allocates an environment, connection, statement, or descriptor handle. This function allocates the related resources in the environment identified by the connection handles and the input environment handles.

SQLAllocConnect() can be replaced by SQLAllocHandle().

Syntax#

SQLRETURN  SQLAllocConnect (
    SQLHENV     env,
    SQLHDBC *   dbc );

Arguments#

Data Type Argument In/Output Description
SQLHENV env Input Environment Handle
SQLHDBC * dbc Output Connection Handle Pointer

Return Values#

SQL_SUCCESS
SQL_INVALID_HANDLE
SQL_ERROR

Description#

The Altibase CLI Driver uses the output connection handle to refer to all information related to the connection such as connection status, transaction status, and error information.

If the pointer (dbc) indicating the connection handle refers to the valid connection handle allocated by SQLAllocConnect(), the calling result will change the original value. If it is application programming error, it is not detected by Altibase CLI Driver.

SQLAllocEnv() must be called before calling this function.

Diagnosis#

SQLSTATE Description Comments
HY000 General error Channel initialization error
HY001 Memory allocation error Failed to allocate the memory for the explicit handle
HY009 Invalid Arguments used (null pointer). dbc is a NULL pointer.
SQLAllocEnv
SQLConnect
SQLDisconnect
SQLFreeConnect

Example#

< Refer to: $ALTIBASE_HOME/sample/SQLCLI/demo_ex1.cpp >

/* Memory allocation for the environment */
if (SQLAllocEnv (&env) != SQL_SUCCESS)
{
    printf("SQLAllocEnv error!!\n");
    return SQL_ERROR;
}

/* Memory allocation for the connection  */
if (SQLAllocConnect (env, &dbc) != SQL_SUCCESS)
{
    printf("SQLAllocConnect error!!\n");
    return SQL_ERROR;
}