SQLDisconnect

Conformance

Version Introduced:ODBC 1.0
Standards Compliance:ISO 92

Summary

SQLDisconnect closes the connection associated with a specific connection handle.

Syntax

SQLRETURN SQLDisconnect(
SQLHDBCConnectionHandle);

Arguments

ConnectionHandle

[Input]
Connection handle.

Returns

SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE.

Diagnostics

When SQLDisconnect returns SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value may be obtained by calling SQLGetDiagRec with a HandleType of SQL_HANDLE_DBC and a Handle of ConnectionHandle. The following table lists the SQLSTATE values commonly returned by SQLDisconnect and explains each one in the context of this function; the notation “(DM)” precedes the descriptions of SQLSTATEs returned by the Driver Manager. The return code associated with each SQLSTATE value is SQL_ERROR, unless noted otherwise.

SQLSTATE Error Description
01000 General warning Driver-specific informational message. (Function returns SQL_SUCCESS_WITH_INFO.)
01002 Disconnect error An error occurred during the disconnect. However, the disconnect succeeded. (Function returns SQL_SUCCESS_WITH_INFO.)
08003 Connection does not exist (DM) The connection specified in the argument ConnectionHandle was not open.
25000 Invalid transaction state There was a transaction in process on the connection specified by the argument ConnectionHandle. The transaction remains active.
HY000 General error An error occurred for which there was no specific SQLSTATE and for which no implementation-specific SQLSTATE was defined. The error message returned by SQLGetDiagRec in the *MessageText buffer describes the error and its cause.
HY001 Memory allocation error The driver was unable to allocate memory required to support execution or completion of the function.
HY010 Function sequence error (DM) An asynchronously executing function was called for a StatementHandle associated with the ConnectionHandle and was still executing when SQLDisconnect was called.

(DM) SQLExecute, SQLExecDirect, SQLBulkOperations, or SQLSetPos was called for a StatementHandle associated with the ConnectionHandle and returned SQL_NEED_DATA. This function was called before data was sent for all data-at-execution parameters or columns.

HY013 Memory management error The function call could not be processed because the underlying memory objects could not be accessed, possibly because of low memory conditions.
HYT01 Connection timeout expired The connection timeout period expired before the data source responded to the request, and the connection is still active. The connection timeout period is set through SQLSetConnectAttr, SQL_ATTR_CONNECTION_TIMEOUT.
IM001 Driver does not support this function (DM) The driver associated with the ConnectionHandle does not support the function.

Comments

If an application calls SQLDisconnect after SQLBrowseConnect returns SQL_NEED_DATA and before it returns a different return code, the driver cancels the connection browsing process and returns the connection to an unconnected state.

If an application calls SQLDisconnect while there is an incomplete transaction associated with the connection handle, the driver returns SQLSTATE 25000 (Invalid transaction state), indicating that the transaction is unchanged and the connection is open. An incomplete transaction is one that has not been committed or rolled back with SQLEndTran.

If an application calls SQLDisconnect before it has freed all statements associated with the connection, the driver frees those statements, and all descriptors that have been explicitly allocated on the connection, after it successfully disconnects from the data source. However, if one or more of the statements associated with the connection are still executing asynchronously, SQLDisconnect returns SQL_ERROR with a SQLSTATE value of HY010 (Function sequence error).

For information about how an application uses SQLDisconnect, see “Disconnecting from a Data Source or Driver” in Chapter 6, “Connecting to a Data Source or Driver.”

Disconnecting From a Pooled Connection

If connection pooling is enabled for a shared environment, and an application calls SQLDisconnect on a connection in that environment, the connection is returned to the connection pool, and is still available to other components using the same shared environment.

Code Example

See SQLBrowseConnect and SQLConnect.

Related Functions

For information about See
Allocating a handle SQLAllocHandle
Connecting to a data source SQLConnect
Connecting to a data source using a connection string or dialog box SQLDriverConnect
Executing a commit or rollback operation SQLEndTran
Freeing a connection handle SQLFreeConnect