Close a connection

To close a connection, free the associated connection descriptor.

When the connection descriptor is freed, the DataBlade® API also frees the session-context resources, including the following:
  • Save sets
  • Prepared statements (explicit statement descriptors)
  • For an SQL statement executed with mi_exec() (also called the current statement):
    • The implicit statement descriptor for the current statement.
    • The row structure and associated row descriptor for the current statement.
  • Cursors (implicit and explicit)
  • Function descriptors
  • Callbacks registered for the connection
  • Connection user data

To conserve resources, use mi_close() to deallocate the connection descriptor explicitly once your DataBlade API module no longer needs it. The mi_close() function is the destructor function for a connection descriptor. It frees the connection descriptor and any resources that are associated with it.

Server only:
In a C UDR, a public connection descriptor has a memory duration of PER_STMT_EXEC. Therefore, a connection descriptor remains active until one of the following events occurs:
  • The mi_close() function closes the specified UDR connection.
  • The current SQL statement completes execution.
When a UDR connection is closed, the UDR can no longer access the associated connection information (see Session-context information in a connection descriptor). However, the session remains open until the client application ends it. Therefore, a UDR can obtain a new UDR connection with another call to mi_open().
Tip: After a C UDR closes a connection, the UDR can no longer access the connection resources in Session-context information in a connection descriptor. Any open smart large objects and operating-system files, however, remain valid for the duration of the session. You can explicitly close these descriptors with the mi_lo_close() and mi_file_close() functions, respectively.

A session-duration connection descriptor has a memory duration of PER_SESSION. Therefore, it and its associated connection information remain valid until the end of the session. However, a session-duration connection is a restricted feature of the DataBlade API. Use it only when a public connection descriptor cannot perform the task you need.

Client only:
In a client LIBMI application, a connection descriptor has a scope of the session. When the client connection closes, the session ends. Therefore, a connection descriptor remains active until one of the following events occurs:
  • The mi_close() function closes the specified connection, ending the session.
  • The client LIBMI application completes.
Tip: After a client LIBMI application closes a connection, it can no longer access the connection information. In addition, any open smart large objects and files are closed.