Product Documentation

c-treeDB API for C++ - Developers Guide

Previous Topic

Next Topic

Connecting to a database

Before performing any operations with a database, a database object must be connected to a session by calling CTDatabase::Connect() method. The database should already have been created or added to the session.

// connect to a database

CTDatabase ADatabase(ASession);

try

{

ADatabase.Connect("MyDatabase");
}

catch (CTException &err)

{
printf("Connect to database failed with error %d\n", err.GetErrorCode());

}

When a database is connected to the session, it is considered "active". Use CTDatabase::IsActive() to check if a particular database is active.

When the database connection is no longer needed, it must be disconnected from the session by calling CTDatabase::Disconnect() method.

// disconnect from a database

try

{

ADatabase.Disconnect();

}

catch (CTException &err)

{
printf("Disconnect from database failed with error %d\n",

err.GetErrorCode());

}

TOCIndex