Updated on 2025-02-27 GMT+08:00

Closing a Connection

The ODBC provides APIs for disconnecting from a database and releasing resources, as shown in Table 1.

Table 1 API description

Function

API

Disconnect from a data source.

SQLDisconnect

Release a handle.

SQLFreeHandle is a generic function for releasing a handle. It can replace the following functions:

The following is an example (for details about the complete example, see Obtaining and Processing Data in a Database):

// Disconnect from the data source and release handles.
SQLFreeHandle(SQL_HANDLE_STMT,V_OD_hstmt);    
SQLDisconnect(V_OD_hdbc);         
SQLFreeHandle(SQL_HANDLE_DBC,V_OD_hdbc);       
SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env);