informix
Informix DataBlade API Programmer's Manual
Establishing a Connection

Establishing the Connection

The following DataBlade API functions are constructor functions for a connection descriptor:

These functions establish a connection and return a pointer to a connection descriptor, which holds information from the session context. You can then pass this connection descriptor to subsequent DataBlade API functions that need to access the session context.

The DataBlade API supports the establishing of the two kinds of connections:

Establishing a UDR Connection

A UDR connection is the way that a C UDR obtains access to the session context; that is, to the database server and database that the calling client application has already established. For a summary of restrictions that the UDR imposes on a session, see Session Restrictions.

The connection descriptor provides the C UDR with access to the session context. The following table summarizes the memory operations for a connection descriptor in a C UDR.

Default Memory Duration Memory Operation Function Name
PER_COMMAND Constructor mi_open()
Destructor mi_close()

To establish a UDR connection, pass all three arguments of mi_open() as the NULL-valued pointer. The following code fragment uses mi_open() to establish a connection for a UDR:

Important: When called within a C UDR, many DataBlade API functions do not use the connection descriptor. However, Informix does not recommend passing in a NULL-valued pointer as a connection descriptor to most DataBlade API functions. Exceptions to this rule are listed in the documentation. Instead, pass in the connection descriptor that the mi_open() function obtains.

The mi_open() call can be expensive in a C UDR. If the UDR instance contains many invocations, you can obtain the connection descriptor the first time the UDR is invoked and store it as part of the MI_FPARAM state information. For more information, see Saving a User State.

Establishing a Client Connection

A client LIBMI application can establish a client connection in either of the following ways:

These DataBlade API functions obtain a connection descriptor for the client connection. The following table summarizes the memory operations for a connection descriptor in a client LIBMI application.

Default Memory Duration Memory Operation Function Name
For the duration of the client session Constructor mi_open(), mi_server_connect()
Destructor mi_close()

Important: When called within a client LIBMI application, DataBlade API functions always use the connection descriptor. Therefore, never send in a NULL-valued pointer as a connection descriptor to DataBlade API functions. Instead, pass in the connection descriptor that the mi_open(), mi_server_connect(), or mi_server_reconnect() function obtains.

Once the client LIBMI application has established a connection, the session begins.

Connections with mi_open()

The mi_open() function establishes a default connection for the calling DataBlade API module and returns a connection descriptor. A default connection is a connection to the default database server (which the INFORMIXSERVER environment variable specifies), and a specified database.

To establish a default connection, the mi_open() function accepts the following information as arguments.

mi_open() Argument Purpose Default Used When Argument is NULL
Database name The name of the database to open None
User account name The name of the login account for the user who is to open the database This account must be valid on the server computer. The name of the system-defined user account (See Figure 7-4 on page 7-12)
Account password The password of the login account for the user who is to open the database This account must be valid on the server computer. The password of the system-defined user account (See Figure 7-4 on page 7-12)

All of these arguments are passed as pointers to character strings. You can specify NULL for any of these arguments, in which case mi_open() uses the specified default values. If the client LIBMI application uses a shared-memory communication, it can only establish one connection per application.

The following code fragment demonstrates the simplest way for a client LIBMI application to initiate a connection to the default database server and to open a database.

In this example, the name of the database to be opened is passed on the command line. The user_name and the user_password arguments to mi_open() are both passed as NULL, which indicates that mi_open() uses the default user and password.

Connections with mi_server_connect() and mi_login()

To exercise more control over which connection to establish, a client LIBMI application can use the following DataBlade API functions:

  1. The mi_server_connect() function establishes the connection to a specified database server.
  2. The mi_server_connect() function obtains information about which database server to connect to from a connection-information descriptor. This function does not open a database.

  3. The mi_login() function opens a specified database.
  4. The mi_login() function obtains information about which database to open from an database-information descriptor.

These DataBlade API functions provide greater flexibility for client LIBMI applications that run against different database servers and databases. They allow you to pass information about the connection and the database through descriptors.


Informix DataBlade API Programmer's Manual, Version 9.2
Copyright © 1999, Informix Software, Inc. All rights reserved