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.
| 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\. For more information on mi_server_connect( ), see Connections with mi_server_connect( ).
Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]