Database Exchange > Working with the Web Client - Introduction > Connecting to a Database
Connecting to a Database

You can connect to either a centralized data source or a distributed data source.

Centralized Data Source

In some applications, users would like to have a centralised data source so that each CitectSCADA client will see the same data. In this case, UNC should be used in the connection string to get access to the file based databases, such as mdb and dbf. To simplify configuration of database access, it would be better to use the direct ODBC connection string.

For example, if you want Web clients to be able to access an Access database (db1.mdb) located on a CitectSCADA server with IP address of (192.168.0.59), the connection string would be:

Driver={Microsoft Access Driver (*.mdb)};Dbq=\\192.168.0.59\MyData\db1.mdb;Uid=admin;Pwd=

where MyData is the shared folder.

The advantage of using the direct ODBC driver connection string is that no ODBC DSN needs to be defined in ODBC Data Sources on CitectSCADA machines, and it is easy to maintain your database and project.

  1. On the Database Exchange configuration form, copy and paste the above connection string to the Database Connection String text box.
  2. Click Build to display the Data Link Properties form, and then click OK to retrieve the database schema. The connection string will be modified since the connection string is reconstructed using the ADO standard and therefore both connection strings are correct.

Distributed Data Source

If you want each CitectSCADA client to run its own copy of the database, you have to deploy the data file with the project, in this case a dbf or mdb file. You also need a dynamic connection string reconstructed at runtime to determine the location of the data file.

For example, a project uses a Database Exchange ActiveX control to display recipes defined in a dbf file (recipes.dbf) in the project folder, and this dbf fill is deployed with the project. You need to define a Cicode function as shown below to construct the connection string and call it in the event of “on page shown” on the page where the control is inserted. Be aware that the connection string is not using a defined ODBC DSN; instead it is using the ODBC DSN connection string for ADO.

// The Database Exchange ActiveX control pasted on page “Test” with AN 36.

// This function is configured as the "On page shown command".

// This function will set the control to use "Microsoft dBase Driver".

// This function will set the init catalog to Citect [run] path.

// This function will load the record inside "Recipes.dbf"

FUNCTION CiRecipe_Init(STRING sAN)

     OBJECT hRecipe =ObjectByName(sAN);

     STRING sDBConString1 ="Driver={Microsoft dBase Driver (*.dbf)}; DriverId=277;FIL=dBase IV;"

     STRING sInitCatalog ="Initial Catalog="+PathToStr("[run]");

     sDBConString1 = sDBConString1 + sInitCatalog;

     _ObjectSetProperty(hRecipe,"DBConString1", sDBConString1);

     STRING sRecordSource1 ="Recipes";

     _ObjectSetProperty(hRecipe,"RecordSource1", sRecordSource1);

END