Previous Topic

Next Topic

Creating a Database object

A valid database object is required to perform any database operation. You need to pass a valid CTSession object to the CTDatabase constructor.

// create a CTDatabase object
CTDatabase ADatabase(ASession);
try
{
// connect to database “MyDatabase”
ADatabase.Connect(“MyDatabase”);
}
catch (CTException &err)
{
printf(“Database connect failed with error %d\n”, err.GetErrorCode);
}

If you create a dynamic CTDatabase object with the new operator, you are required to destroy the object with the delete operator.

// create a dynamic CTDatabase object
CTDatabase* pDatabase = new CTDatabase(ASession);

if (!pDatabase)
{
   printf(“CTDatabase creating failed\n”);
}  
... other operations ..
// destroy the CTDatabase object
delete pDatabase;

If you destroy an active database handle, all open tables associated with the database will be closed and the database will be disconnected from the session.