SQLDisconnect - Disconnect from a data source

Purpose

SQLDisconnect() closes the connection associated with the database connection handle.

After calling this function, either call SQLConnect() to connect to another database, or call SQLFreeConnect().

Syntax

SQLRETURN SQLDisconnect (SQLHDBC    hdbc);

Function arguments

Table 1. SQLDisconnect arguments
Data type Argument Use Description
SQLHDBC hdbc Input Connection handle

Usage

If an application calls SQLDisconnect before it has freed all the statement handles associated with the connection, DB2® UDB CLI frees them after it successfully disconnects from the database.

If SQL_SUCCESS_WITH_INFO is returned, it implies that even though the disconnect from the database is successful, additional error or implementation specific information is available. For example:
  • A problem is encountered on the clean up after the disconnect, or,
  • If there is no current connection because of an event that occurred independently of the application (such as communication failure).

After a successful SQLDisconnect() call, the application can re-use hdbc to make another SQLConnect() request.

If the hdbc is participating in a DUOW two-phase commit connection, the disconnect might not occur immediately. The actual disconnect occurs at the next commit issued for the distributed transaction.

Return codes

Diagnostics

Table 2. SQLDisconnect SQLSTATEs
SQLSTATE Description Explanation
01002 Disconnect error An error occurred during the disconnect. However, the disconnect succeeded. (Function returns SQL_SUCCESS_WITH_INFO.)
08003 Connection not open The connection specified in the argument hdbc is not open.
25000 Transaction state that is not valid There is a transaction in process on the connection specified by the argument hdbc. The transaction remains active, and the connection cannot be disconnected.
58004 System error Unrecoverable system error.
HY001 Memory allocation failure The driver is unable to allocate memory required to support the processing or completion of the function.
HY013 * Memory management problem The driver is unable to access memory required to support the processing or completion of the function.

Example

Refer to the example in SQLAllocEnv - Allocate environment handle.

References