Connect to CDB#

See also

Visual Basic for Applications - Examples

Problem Description#

To connect to the CDB, the project must be configured (see Configure project). The example below shows how to connect to the CDB.

Problem Solution#

An example can be found by following:

C:\<sofistik_installation>\2024\SOFiSTiK 2024\interfaces\examples\c++\connect_to_cdb

The folder contains:

  • connect_to_cdb.sln (folder)

  • connect_to_cdb_vcxproj

  • main.cpp

Open the Visual Studio Solution .sln and change the fileName path in the main.cpp

char* fileName = "S:\\test\\cdbPath.cdb";
C++ - Connect to CDB#
int main()
{
   // In this example debug 64bit dlls are used (Visual Studio Platform 64bit)

   // Connect to CDB
   // int sof_cdb_init  ( char* FileName, int Index);

   /*
   Index = 0     initialise CDBASE and open scratch data base only
   Index > 0     open an existing data base with exactly tis index
                        (STATUS=UNKNOWN) = somehow obsolete call, use 99!
   Index = 99    test if NAME is a valid database and open the base
                        if possible. Return with the assigned index.
                        If the file does not exist, it will be created.
   Index = 97    open the database via pvm
                        Return with the assigned index.
   Index = 96    open a scratch database, filename is the path to
                        use or NULL.
   Index = 95    open in read-only mode
   Index = 94    create a new data base (STATUS=NEW)
   */
   int index = 99;
   char* fileName = "S:\\test\\cdbPath.cdb";
   int ie = sof_cdb_init(fileName, index);
   if (ie < 0)
   {
      cout << "ERROR: Index= " << ie << " < 0 - see clib1.h for meaning of error codes" << endl;
      cout << "Press any <key> to close the program";
      system("pause");
      return(0);
   }
   else if(ie == 0)
   {
      cout << "ERROR: Index= " << ie << " - The File is not a database" << endl;
      cout << "Press any <key> to close the program";
      system("pause");
      return(0);
   }

   // Get Status
   // int sof_cdb_status  (int ie);
   cout << "The CDB Status: " << sof_cdb_status(ie) << endl;

   // Close the CDB
   // int sof_cdb_close  (int ie);
   sof_cdb_close(0);
   cout << "The CDB Status after closing: " << sof_cdb_status(ie) << endl;

   system("pause");
   return 0;
}