Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic


Connect to a database.


CTDBRET ctdbConnect(CTHANDLE Handle, pTEXT Name)


ctdbConnect() connects a database handle to a database. Connecting to a database makes that database "active." Before using this function to connect to a particular database, you must first allocate the database handle and associate it with a session by calling the ctdbAllocDatabase() function. In other words, after allocating a database handle and associating it with a session, use this function to select which database in the session the database handle manipulates. The application must connect a database before doing any operation with that database's tables.

  • Handle [in] the database handle, previously allocated with ctdbAllocDatabase().
  • Name [in] the database name. This database must have been previously added to the session with ctdbAddDatabase().

To disconnect a database from session, use the functions ctdbDisconnect() or ctdbDisconnectAll().


ctdbConnect() returns CTDBRET_OK on success, or the c-tree error code on failure.


CTHANDLE hMyDatabase;

hMyDatabase = ctdbAllocDatabase(hMySession);

eRet = ctdbConnect(hMyDatabase, database_name);

See also

ctdbAllocDatabase(), ctdbDisconnect(), ctdbDisconnectAll(), ctdbCreateDatabase()