Product Documentation

FairCom ODBC

Previous Topic

Next Topic

Init

First we need to open a connection to a database by providing the FairCom Database Engine with a user name, password and the database name.

Below is the code for Initialize():

/*

* Initialize()

*

* Perform the minimum requirement of logging onto the c-tree Server

*/

void Initialize(void)

{

RETCODE rc;

printf("INIT\n");

/* allocate environment handle */

if ((rc = SQLAllocEnv(&hEnv)) != SQL_SUCCESS)

Handle_Error(0, NULL, "SQLAllocEnv()");

/* allocate connection handle */

if ((rc = SQLAllocConnect(hEnv, &hDbc)) != SQL_SUCCESS)

Handle_Error(SQL_HANDLE_ENV, hEnv, "SQLAllocConnect()");

/* connect to server */

printf("\tLogon to server...\n");

if ((rc = SQLConnect(hDbc, MY_DSN, SQL_NTS, "admin", SQL_NTS, "ADMIN", SQL_NTS)) != SQL_SUCCESS)

Handle_Error(SQL_HANDLE_DBC, hDbc, "SQLConnect()");

/* allocate statement handle */

if ((rc = SQLAllocHandle(SQL_HANDLE_STMT, hDbc, &hStmt)) != SQL_SUCCESS)

Handle_Error(SQL_HANDLE_DBC, hDbc, "SQLAllocHandle(SQL_HANDLE_STMT)");

}

TOCIndex