Merging Two Databases Using the LabVIEW DSC Module

Updated Oct 31, 2023

Environment

Software

  • LabVIEW Datalogging and Supervisory Control Module

When you log data using the LabVIEW Datalogging and Supervisory Control (DSC) Module, you have two options for manipulating the database files. One option is to use the Historical Data Viewer in Measurement & Automation Explorer (MAX). This option is useful when the manipulation of the database does not need to be done programmatically. The other option is to use the Historical VIs in the DSC Module. You can use these VIs to archive data when logging to a directory, merge data with other databases, and collect data from other computers. Using the Archive Traces VI, you can copy a database from one directory into a different directory. The Archive Traces VI can archive the database while the database is logging new data points. You can archive two databases depending on their location. The following sections explore two cases involving archiving historical databases. To explore these cases further the files are also attached to this document.

Case 1: Merging Two Databases Logged on the Same Computer

To merge two databases on the same computer, you can use the Archive Traces VI. Suppose you have two databases, databaseA and databaseB. Use the Historical Trend Express VI to display the data of both databases, as shown in the following figures.

Figure 1. Historical data in databaseA

Figure 2. Historical data in databaseB

The following figure illustrates the front panel and block diagram of a VI that merges databaseA and databaseB. You specify the location of databaseA and the location of the databaseB in the First Database control and Second Database control, respectively. The Archive Traces VI combines the data in databaseA with the data in databaseB and stores the data in the same directory as databaseB. Refer to the following figure for the front panel and block diagram to merge these two databases.

Figure 3. Front panel of merging one database into the directory of another


Figure 4. Block diagram of merging one database into the directory of another

The block diagram in the previous figure shows an example of using the Archive Traces VI to combine all the data in both databases. The following figure displays the data of databaseB after combining all the data.

Figure 5. Data of databaseB after the merging

Note: You can archive selected data by wiring the Trace Names input to the Archive Traces VI. 

You can also use the Archive Traces VI to merge the data of two databases together and store the data into a new directory. In this case, you need to use the Archive Traces VI twice. The first Archive Traces VI stores the data of databaseA into the new directory. The second Archive Traces VI merges databaseB with databaseA in the new directory. The following figure illustrates the front panel and block diagram of a VI that merges the two databases into a new directory.

Figure 6. Front panel of merging two databases into a new directory


Figure 7. Block diagram of merging two databases into a new directory

According to the previous figure, the Archive Traces VI merges databaseA and databaseB into a new database and stores the data in the newdatabase directory.
 

Case 2: Merging Two Databases Logged on Different Computers

A use case where you want to merge two databases logged on different computers is redundancy. In a redundancy system, the primary computer logs to its own database. When the primary computer logs off, the secondary computer takes control and logs data to its own database. After the primary computer logs on again, you need to merge the database on the secondary computer to the database on the primary computer to fill in the data gap.

You can use the Archive Traces VI to merge two databases logged on different computers. Suppose that you have two computers monitoring temperature data, TestPC1 and TestPC2. After both computers finish logging data, you want to merge the databases on both computers into one computer, TestPC1. Use the Historical Data to view the database on each computer, as shown in the following figures.

Figure 8. Database on TestPC1


Figure 9. Database on TestPC2

You must complete the following tasks to merge the databases on both computers into TestPC1.

1. Manually copy the database from TestPC2 to a new folder on TestPC1.

Note: To manually copy the database, you must stop the Shared Variable Engine (SVE)  and the Logos services. Refer to the LabVIEW Help to learn how to stop the SVE. If you cannot stop the Logos services, use the Detach Database VI in the DSC Module to detach the database before copying the database. Refer to the LabVIEW Help for more information about the Detach Database VI. If you create a copy of the database while the SVE or the Logos services are running, you might get an inconsistent copy of the database. If you cannot stop the engine or the services, use the Archive Traces VI to make a copy programmatically.

2. Rename the data in the database on TestPC2 to match the trace names in TestPC1 using the Rename Historical Data VI. 

For example, the data logged in the process named LabVIEW (the default process name) on TestCpu2 has the following prefix:
\\TestCpu2\LabVIEW\...

The data logged in the process named MyLabVIEWProcess (the edited process name) on TestCpu1 has the following prefix:
\\TestCpu1\MyLabVIEWProcess\...

Note: You do not need to name these data with the same name. However, if the data on both computers represent the same traces but are logged from different computers, you can keep the same name for the traces when merging the databases.


3. Merge the two databases into a new database directory using the Archive Traces VI. The following figure is an example of the front panel and block diagram of a VI that merges two databases logged on different computers. Notice that the names of the traces are different and are renamed.

Figure 10. Front panel of merging two databases logged on different computers


Figure 11.  Block diagram of merging two databases logged on different computers

4. View the new database in the Historical Data Viewer to verify that the merging is complete. You can also use the NI HyperTrend control in LabVIEW to view the data.

The following figure displays the database after merging two databases logged on different computers.


Figure 12. Merged database consisting of data logged from TestCpu1 and TestCpu2
 

Summary

In applications that require merging two databases, you can use either the Historical Data Viewer in MAX or the Historical VIs in the DSC Module. Using the Archive Traces VI, you can copy a database from one directory into a different directory on the same computer without stopping the logging process. You also can use the Historical VIs to merge the databases logged on different computers.