10.2. Quick Start

Here's how to configure a DataHub instance to query a database of your choice.

Click here to watch a video.

Procedure 10.1. Open the Query ODBC Database window
  1. In the DataHub Properties window, select Database.

  2. In the Query a Database (ODBC) section, click the Configure button.

    This opens the Query a Database (ODBC) window, shown below.

Procedure 10.2. Connect to the Database
  1. Select the 1. DSN tab. A DSN is a Data Source Name. Windows uses this name to identify the database you want to connect to.

  2. From the drop-down box, select a DSN. If you do not have any DSNs, or you wish to create a new DSN, you can do this by opening the DSN Administrator. Please refer to Setting up a DSN for more details.

  3. Enter the user name and password (if required), and click the Connect button. A "Connected to ..." message should appear in the message box. If you get an error message in the box, consult your system administrator.

Procedure 10.3. Configure a Query
[Note]

For this and other queries in this chapter, we will use a simple example database named test with a table named querytest that has 4 columns and 3 rows.

In our example, we will be writing the contents of the VariableName and VariableValue columns to the DataHub instance.

  1. Select the 2. Query tab.

  2. In the Label: field, enter a name for this query, such as TestQuery. This can be any string.

  3. Enter a valid SQL query. As an example, for our small database, we can use a simple SQL query:

    SELECT * FROM	database.table LIMIT 3;
    [Note]

    If you use a SELECT * FROM query like this on a large database with a frequent timer, we recommend limiting the number of rows returned, to prevent hanging the database.

  4. Press the Submit button to submit your query to the database for a check. If the query is not valid, a message will pop up informing you about any errors. You can also open the Script Log to see more information about your connection to the database, and the results of your query.

  5. There are two options for how a query is written to the DataHub instance. Here we will introduce the One point per row option. For information about the Whole data set in a point option, please refer to Section 10.4, “Configuring a Database Query”.

    Select One point per row.

  6. In the Column Name / Point Name dropdown list, choose the column name in your database that contains the point names that you will be using. For instance, in our demo database that column is named VariableName.

  7. In the Column Name / Value dropdown list, choose the column name in your database that contains the values for the point names that you will be using. For instance, in our demo database that column is named VariableValue.

  8. In the Replace domain field, enter the name of a new or existing domain. We've put in a name for a new domain, TestDomain.

  9. Click the Create button.

    A new configured action should appear in the list. For more information about configured actions, please refer to Section 10.7, “Configured Actions”

    Next, to get the DataHub instance to make the query, you need to assign a trigger.

Procedure 10.4. Assign a Trigger

For this example, we will set a repeat timer to re-query the database every 5 seconds.

  1. Select the 3. Trigger tab.

  2. Select Repeat Timer and enter 5.

  3. In the Configured Actions box, make sure that the configured action you just created is highlighted. If not, click on it to highlight it. Then click the Modify button.

    Your configured action should now display every 5 sec in the Trigger column.

  4. Click the Apply button to activate the configured action.

  5. Open the Data Browser window. After 5 seconds, the points should appear in the Data Browser:

    To test the updates, you can change a value associated with a point name in the database, and the change should appear in the Data Browser within 5 seconds.

    Should you not see the data points, or changes made to the values, you can open the Script Log to check for error messages and ensure that your query is being sent every 5 seconds.

If all is working as described, you have configured an action that queries a database for and writes the results into the DataHub instance. The remaining sections in this chapter explain the interface in more detail, and introduce the option of setting specific conditions for queries, if desired.