3.2. Interactions with the Database

3.2.1. Connecting to the Database

Connecting to an ODBC database is a three-step process:

  1. Create an ODBCEnvironment object.

  2. Create an ODBCConnection object.

  3. Connect to a DSN (Data Source Name).

    .env = ODBC_AllocEnvironment();
    .conn = .env.AllocConnection();
	
    /* Attempt to connect. */
    ret = .conn.Connect ("DSN name", "user name", "password");
    if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO)
        error (.conn.GetDiagRec());

If the connection fails, the return value will be something other than SQL_SUCCESS or SQL_SUCCESS_WITH_INFO. You can query the database for details of the failure by calling the GetDiagRec method of the ODBCConnection.