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 the CTDatabase.Connect() method. The database should already have been created or added to the session.


// connect to a database

CTDatabase ADatabase = new CTDatabase(ASession);


try

{

ADatabase.Connect("MyDatabase");

}

catch (CTException err)

{

Console.Write("Connect to database failed with error {0}\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 the CTDatabase.Disconnect() method.


// disconnect from a database

try

{

ADatabase.Disconnect();

}

catch (CTException err)

{

Console.Write("Disconnect from database failed with error {0}\n", err.GetErrorCode());

}

TOCIndex