SQLDisconnect - Disconnect from a data source
SQLDisconnect()
ends
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
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® for
i CLI frees them after
it successfully disconnects from the database.
- 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
- SQL_SUCCESS
- SQL_SUCCESS_WITH_INFO
- SQL_ERROR
- SQL_INVALID_HANDLE
Diagnostics
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.