Access by data source
Usually, databases can be opened by [creating or opening a client handle], creating a dictionary handle and creating/opening a database and object space handle. Database locations have to be passed to those functions, which is simple but reduces flexibility of the program.
Accessing the database via predefined data source provides more flexibility to the application. There is still a client object required, but the location for database and dictionary can be provided externally in a data catalog or in an ini-file.
The example below shows, how to open the Sample database data source defined in the "sample.ini" configuration file. The section in the configuration file (or xml element in an xml configuration file) must have got the name referred to as data source name in the openDataSource() function ("Sample"). Details for defining data sources are described in the"Database References" manual under DataSource.
Instead of using a configuration or ini-file, one may also create a data source and fill in the details. The data source allows defining all access parameters before opening.
The example below illustrates two ways of accessing (opening) a data source. The first opens a database with fixed parameters defined in the program. The second shows one way of opening the same database but controlled by options defined in an ini-file.
// open static resources
Dictionary dict;
Database db;
dict.open("c:/odaba/sample/sample.dev");
db.open(dict,"c:/odaba/sample/sample.dat",Write,true);
// open data source parametrized in an ini-file (Sample.ini):
// [Sample]
// DICTIONARY=c:/odaba/sample/sample.dev
// DATABASE=c:/odaba/sample/sample.dat
// ACCESS_MODE=Write
// NET=YES
ObjectSpace db;
Application.initialize("c:/sample/sample.ini","MyAppl",ConsoleApplication);
db.OpenDataSource("Sample", Write);