Set connection parameters for a client connection

The following example shows one way to set default connection parameters. Assume that the system-default connection parameters are as follows.
System-default parameter Parameter value
Default database server joe

(INFORMIXSERVER environment variable is set to "joe.")

Default user tester
Default user password No password
Callbacks enabled? Yes (system default)
Pointers checked? Yes (system default)
The following code fragment uses DataBlade® API functions to change the following default system values listed in the table.

The following table shows the default parameters for the mi_set_default_connection_info() function and the mi_set_default_database_info(). For each of these functions, there are two default parameters. The table also shows the default value for the parameter. If there is no default parameter, the default value is none.

DataBlade API function Default parameter Default value
mi_set_default_connection_info() Database server name beth
Server port = 0 None
mi_set_default_database_info() Database name template1
User-account name miadmin
User-account password No password
extern void MI_PROC_CALLBACK all_callback();
MI_CONNECTION                     *conn;
MI_CONNECTION_INFO                     conn_info;
MI_DATABASE_INFO                     db_info;

/* Initialize DataBlade API */
mi_register_callback(conn, MI_Exception, all_callback,
   NULL, NULL);

/* Assign default connection parameter in the 
 * connection-information descriptor
 */
conn_info.server_name = "beth";
conn_info.server_port = 0;

/* Set default connection parameters for the application */
if ( mi_set_default_connection_info(&conn_info) == MI_ERROR )
      printf("FAILED: mi_set_default_connection_info()\n");

/* Assign default database parameters in the 
 * database-information descriptor
 */
db_info.user_name = "miadmin";
db_info.database_name = "template1";
db_info.password = NULL;

/* Set default database parameters for the application */
if ( mi_set_default_database_info(&db_info) == MI_ERROR )
      printf("FAILED: mi_set_default_database_info()\n");

/* Get default connection and database parameters for
 * application
 */
mi_get_default_connection_info(&conn_info);
mi_get_default_database_info(&db_info);

/* Make sure the right database server is set as the default */
if ( strcmp("beth", conn_info.server_name) != 0 )
   printf("FAILED: got server_name %s, should be beth\n",
      conn_info.server_name);

/* Connect to database server 'beth' */
conn = mi_server_connect(&conn_info);
if ( conn == NULL )
   printf("FAILED: CONNECT to beth\n");
else
   {
   printf("OK: connected to %s\n", conn_info.server_name);
}

After these new defaults are established, the application calls mi_server_connect() to request a connection to the beth database server. If this request is successful, the application opens the template1.