Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


HTML
<style>
.text-span-6 {
    background-image: linear-gradient(99deg, rgba(170, 163, 239, .5), rgba(125, 203, 207, .5));
    border-radius: 50px;
    padding-left: 15px;
    padding-right: 15px;
}

#title-text {
display: none;
}

.panelgradient {
    background-image: linear-gradient(180deg, #d5def0, whitesmoke);
    border-radius: 8px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 4rem;
    display: flex;
    position: relative;
}

</style>


<div class ="panelgradient">

<h1 style="text-align: center;">Datasets <br> (Databases and SQL Queries)</h1>

</div>



Introduction to the Datasets Module

The Datasets Module is designed for data exchange with SQL databases and text files from a diverse set of sources. Essentially, the Dataset module Datasets Module drives bi-directional real-time communication between all Project Modules modules and the SQL databases. 

This module offers compatibility with various database technologies, including ADO.NET, ODBC, OleDB, and native interfaces, providing straightforward configuration with prominent databases such as SQL Server, Oracle, SQLite, and PostgreSQL. Features include multi:

  • Multi-threaded concurrent connections with multiple databases for efficient data handling
  • SQL Query editor, SQLite admin tool, and a Visual Query Builder, streamlining the configuration experience
  • Customization of SQL statements in real-time with tags and system events

Image Added a dedicated SQLite editor for streamlined database management, and an intuitive visual query builder that simplifies the process of query creation and manipulation. The Dataset module also integrates real-time tags within query strings, enhancing the dynamism of data interaction. It can manage files and recipes in ASCII, Unicode, or XML formats, broadening its applicability across different data types.

On this page:

Table of Contents
maxLevel3
minLevel2
stylenone


Key Concepts and Terms

DatasetDB

Connections settings created by

Panel
bgColor#ffffff

DatasetDBs

For

the Dataset Module to communicate with an external database

, a connection must be created with specific parameters. These connections, created within the Datasets → DBs section of the module, are referred to a DatasetDB.
Panel
bgColor#ffffff

DatasetQueries

In the context of the Dataset Module, a DatasetQuery refers not only to an SQL query string but also to a solution object that has a logical name, an SQL query related to that logical name, and other parameters defined within the Datasets → Queries section. The DatasetQuery allows to customize the SQL statements with tags evaluated in real time, as well to use its result in the real-time application.

Panel
bgColor#ffffff

DatasetTables

A DatasetTable is a logical name created within a solution to set up access to a specific table in a connected database. These tables are listed within the Datasets → Tables section of the module. The tags in the real-time database can be easily mapped to columns in the tables to perform insert, update, or read operations.

Panel
bgColor#ffffff

DatasetFiles

A Dataset File is a logical name that defines parameters for reading and writing files in ASCII, Unicode, or XML formats.

Understanding the Datasets Module

The Datasets Module enables users to interact with SQL databases seamlessly, allowing them to retrieve and manipulate data within their applications.  Here you can:

  • Generate Custom Visualizations,
  • Implement Intricate Logic
  • Set Up Dynamic Alarms

The module supports real-time Tags within query strings, and manages files and recipes in ASCII, Unicode, or XML formats.

Module Highlights

  • Multi-threaded concurrent connections for efficient data handling.
  • Dedicated SQLite editor for streamlined database management.
  • Intuitive visual query builder that simplifies the process of query creation and manipulation.

Data Utilization

The data retrieved from databases can be utilized in various ways throughout your project:

  • In the Displays Module: Visualization tools like DataGrids can present query results on screens and dashboards, creating custom views of the data that are accessible and easy to understand for your users.
  • In the Scripting Module: Custom scripts can reference query results and trigger specific actions, such as sending notifications, updating tags, or performing calculations, thereby implementing complex logic based on database data.
  • In the Alarm Module: Data can be used to configure or update alarm conditions, triggers, and actions, enabling the creation of dynamic alarm systems that respond to data changes.

Various modules can also add data to your SQL databases. For instance, the Displays Module can log operation inputs and commands, the Scripting Module can calculate analytics, and the Alarm and Historian Modules can retain long-term records and audit trails. 

Processing Data Requests

Datasets Data Server Service

The Datasets Data Server Service ensures high performance and seamless integration while exchanging structured collections of data in real-time. It efficiently processes data requests from other modules, enabling connectivity with various components such as HMI/SCADA screens, scripting, and reporting tools.

Default Databases Used When Running the Project

The Dataset module also serves as a data storage configuration hub for other modules. The Alarm and Historian modules, which generate events and records for long-term retention, utilize the Dataset module for defining data storage. Similarly, the Security Module can utilize user definitions from an external database defined within the Dataset module.

Data Source Virtualization

Data Source Virtualization is an advanced feature that simplifies data management across multiple data sources. It provides a unified interface for accessing, querying, and manipulating data, regardless of the underlying data storage technology. This feature allows modifications to the underlying data sources repositories without impacting the rest of the application.

  • Agnostic, Standards, Centralized Management

Adhering to industry standards, the module is designed to work seamlessly with various data storage technologies. It enables centralized management of data connections and configurations, streamlining the process of integrating different data sources into your projects.

→ Read more about Advanced Datasets Topics.

.

DatasetQuery

Logical name associated with the configuration for SQL query statements with a Database, and its properties and methods for running que queries.  

DatasetTable

Logical name created to hold configuration settings to access specific tables in a connected database, mapping tags to table columns for operations.

DatasetFile

Logical name defining parameters for reading and writing files in ASCII, Unicode, or XML formats.


Understanding the Datasets Module

The Datasets Module enables users to interact with SQL databases seamlessly. The module supports real-time Tags within SQL statements, and manages files and recipes in ASCII, Unicode, or XML formats.

The data retrieved from databases can be utilized in various ways throughout your solution. For example:

  • In the Displays Module: Visualization tools like DataGrids can present query results on screens and dashboards, creating custom views of the data that are accessible and easy to understand for your users.
  • In the Scripting Module: Custom scripts can reference query results and trigger specific actions, such as sending notifications, updating tags, or performing calculations, thereby implementing complex logic based on database data.
  • Devices:  Sending data from field equipments to a SQL database, or applying settings from the database to the field equipments.

Pre-defined Database Connections

The Dataset Module also serves as a data storage configuration hub for other modules. The following Database connections are pre-defined by the Dataset Module.

  • AlarmHistorian: Events and records for long-term retention.
  • TagHistorian: Time-series storage for process variables,
  • RuntimeUsers: Dynamics users and credentials created when running the solution.
  • Retentive: Persistent records for tags and properties that need to be kept across multiple starts of the solution (typically configuration settings and setpoints).

Processing Data Requests

The Datasets Module has its implementation running as a service, which ensures high performance and real-time responses to multiple client requests.

This architecture also enhances protection and security for the database, as client displays and scripts won't access the databases directly, but through the Datasets Service.

Another benefit is the ability for Data Source Virtualization, meaning that when the solution is using Dataset.Query.Query1 in its displays or scripts, the database running that query, along with the query itself, can be maintained or replaced without affecting the overall solution configuration. This feature allows the solution to work with the data, regardless of the underlying data storage technology.

For an advanced deeper understanding of the Datasets Services, see Dataset Advanced Topics.


Configuring the Datasets Module

Configuration Workflow

The typical configuration workflow for the Dataset module has the following sequence:

Datasets Module Configuration Workflow

Action

Where 

Comments

Define database connections

Datasets→DBs

Gather connection details for your applications databases and created DB objects as need. Leverage the built-in SQLite admin tool for temporary development purposes

Prepare Queries

Datasets→Queries

DataExplorer→SQL

VisualQueryBuilder

Queries to craft queries using the built-in SQL Language Editor, the  VisualQueryBuilder or using provided SQL statements from other sources.

Fine-tune queries adding real-time parameters. Eg.: Transform "WHERE col1 = 5" to "WHERE col1 = {{tag.Test}}".

Map Database Tables

Datasets→Tables

Optionally, you can establish a direct mapping to tables within the Database. 

Map Recipes and Text files

Datasets→ Files

Optionally, your solution may need to save or load recipes, or other information, from ASCII, Unicode, or XML files. 

Managing DB Connections

There are four database connections pre-defined in

Configuring the Datasets Module

  • First, access Datasets → DBs and establish a database connection. After creating a DB, input the server path in the Connection String property.
  • Access Datasets → Queries to create Queries using the visual Query Editor or Provided SQL Strings.

    Tip
    titleUse Meaningful Names

    We recommend names such as, Dataset.Query, to identify Query Usage, to improve the solution maintenance.

    Info
    titleEnhance Query Flexibility with Real-Time Parameters

    Adding real-time parameters to your queries offers flexibility and adaptability, enabling dynamic data retrieval based on changing conditions. Instead of hardcoding specific values, you can use dynamically populated placeholders at runtime. 

    Instead of using Queries like the following:

    • SELECT * FROM your_table WHERE col1 = 5

    Use Queries with real-time parameters:

    • SELECT * FROM your_table WHERE col2 = {{tag.Test}} 

    In this example, {{tag.Test}} serves as a placeholder for a real-time parameter.

  • Access Datasets → Tables to manage your project tables and connect inserted data with Tags for efficient data handling.
  • Establish file-based data exchange configurations at Datasets → Files. You can configure interactions with plain text or XML files as needed.
  • Finally, leverage logically named objects throughout the solution, applying them in script calculations, visualization displays, and other components.
  • Info

    You can also configure and execute Stored Procedures at Datasets → Queries to extend the Query's functionality.

    ** Why is there an anchor below? What links go to this? **

    AnchorConnectionsConnectionsManaging DB Connections

    When using SQLite databases, the Dataset Module can automatically create the database locally if it doesn't already exist. For other database types, the database itself must already exist before you set your connection.

    Info

    Any user can create new connections in the solution. However, only the Administrator can configure database login passwords.

    There are four database connections preloaded into any new solution.

    Datasets DB - Pre-defined database connections

    DB

    Database

    Path Location

    Usage

    Retentive

    SQLite

    <ProjectNameAndPath>.dbRetentive

    Stores values for

    Retentive Tags

    the Tags with the Retentive property set.

    RuntimeUsers

    SQLite

     <ProjectNameAndPath>.dbRuntimeUsers

    Stores dynamically created

    Users

    Solution SecurityUsers.

    AlarmHistorian

    SQLite

     <ProjectNameAndPath>.dbAlarmHistorian

    Stores Alarm and AuditTrail records.

    TagHistorian

    SQLite

    <ProjectNameAndPath>.dbTagHistorian

    Stores Tag Historian and Annotations.

    If needed to use another database for the pre-defined connections, follow these steps below:

  • Rename or delete the previous DB. This step is necessary, as the system would not allow the creation of two objects with the same name. 

  • Stores Tag Historian and Annotations.


    When using SQLite databases, the Dataset Module can automatically create the database locally if it doesn't already exist. For other database types, the database itself must already exist before you set your connection

    Create a new DB with the same name as the previous DB, with the required database and connection settings

    .

    → Read more about Dataset Datasets DBs.

    Dataset Queries DatasetQueries Configuration

    Users can enhance data manipulation by configuring queries with SQL statements in the Dataset module. The Visual Query Editor simplifies the process, allowing users to drag and drop tables, define relationships, and apply filters through an intuitive graphical interface.

    → Read more about the Visual SQL Query Builder.

    Queries can be saved and executed seamlessly within the module. Use the DatasetQueries to define SQL Statements, for queries and stored procedures to execute in connection of the created DatasetDB databases. 

    Read more about Dataset Datasets Queries.

    Dataset Tables DatasetTables Configuration

    Use the Dataset Tables to manage data tables and configure table properties such as structure, relationships, and data types. It provides an intuitive interface to streamline customization and ensure efficient data handling. DatasetTables to access or exchange data with databases tables, with simplified query syntax. It allows allow insert new rows directly on database tables.

    Read more about Dataset Datasets Tables.

    Dataset Files DatasetFiles Configuration

    The Dataset files DatasetFiles are used to customize file interactions in the Dataset moduleModule. With this feature you can configure file-related properties, define formats and establish connections. read or write realtime tags to ASCII, Unicode and XAML files.

    Read more about Dataset Datasets Files.


    Working with the Datasets

    module

    Module

    Runtime Execution

    One of the critical features of the Datasets module is the ability to execute SQL queries and retrieve data in real-time. Here are some ways to leverage the Runtime execution features of the Dataset module:

    • Create SQL queries to retrieve data from external databases.
    • Use query results to trigger events and actions within the platform environment.
    • Configure event triggers based on specific query criteria, such as changes to a particular data point or an exceeded threshold value.

    Monitoring the Datasets Module

    Intra-Module Interaction

    The Datasets module easily integrates with other modules within the software environment. Here are some examples of how to use the Dataset module in conjunction with other modules:

    • Displays Module: Visualization tools like Data Grids can present query results on screens and dashboards, creating custom views of the data that are accessible and easy to understand for your users.
    • Scripting Module: Custom scripts can reference query results and trigger specific actions, such as sending notifications, updating tags, or performing calculations, thereby implementing complex logic based on database data.
    • Alarm Module: Data can be used to configure or update alarm conditions, triggers, and actions, enabling the creation of dynamic alarm systems that respond to data changes
    • Unified Namespaces Module: You can utilize Tags from your project as dynamic placeholders within SQL queries or file names. This capability facilitates real-time data manipulation within the query strings. Moreover, you can map the results of the queries to Tags or employ Tags to populate values when inserting or modifying existing records. 

    The Datasets module drives bi-directional real-time communication between all Project Modules and the SQL databases. By leveraging these integration options, users can gain greater insight and control over their data sources within the platform. They can execute SQL queries and trigger actions based on query results, providing robust tools for working with data.

    External System Interaction

    The Dataset module enables seamless interaction with external databases, enhancing data integration and accessibility. The following is a list of possible databases you can connect:

    • SQL Server
    • PostgreSQL
    • Excel

    When executing the solution, there is an infrastructure of services that manages access to the database and transports that information to where it is requested. For instance, to display a Dataset Query result on an HTML5 page, that request first goes to the server, which then requests the database (which can be on another computer), and the information flows back to the requester.

    As database operations can take some time to execute, it is very important to understand some aspects of the Datasets Module execution, including the concept of synchronous vs. asynchronous requests.

    The page Datasets Module Execution details concepts that describe the module's internal operations.

    Showing DataGrids Tables on Displays

    One typical use of the Dataset Module is to display query results on displays and dashboards.

    In order to so, create or DatasetQuery, or DatasetTable, then use the DataGrid Control on your displays.

    Using Query Results on Scripts and Tags

    It's possible to define the SQL statements with code (either using the Scripts Module or Display CodeBehind) and connect the results with tags early on.

    The property Dataset.Query.Query1.SqlStatament holds the query that will be executed; just modify that property within your scripts. 

    The Tag Type DATATABLE was created to be compatible with results of Select() statements. SImply apply the results to your query and use tags no manage the information. 

    The TK (Toolkit extension for Scripts) has methods that allow for easy copying between DataTables (query results) and Template Tags, like TK.CopyTagToDataTable().

    Monitoring Databases Connection Status

    Monitoring Database Connections is an essential aspect of maintaining a reliable operation of the solution. 

    This can be accomplished using the Dataset Namespace properties, which provide status for DatasetTables and DatasetQueries operations.

    Read more about Datasets Runtime Attributes.

    During the Development phase, when the Designer tools is connected with a Runtime (the Solution is in execution), the main status conditions can be seen in the monitoring page.

    Read more about Datasets Monitor


    Datasets Advanced Topics

    Datasets Module Execution

    The Dataset module facilitates efficient database interactions by utilizing TServer services, manageing managing synchronous and asynchronous executions for optimal performance.

    Read more about Databases Connection And Interactions.

    Data Management

    The Dataset Module offers versatile methods for managing data and concurrency within solutions, including Data Table tags and Async Contents.

    Read more about Data Management.

    Datasets Runtime Attributes

    The Datasets Namespace exposes properties and methods from the .NET objects used by the Historian Module execution. You can use these properties and methods on your Displays or to create Scripts and Alarms.

    Read more about Dataset Datasets Runtime Attributes.

    Preventing SQL Injections

    See page Datasets Advanced Topics

    Network Gateway Access And Time Zone Handling

    See page Datasets Advanced Topics

    Backup Of Solutions SQLite Data Bases

    →See See page Datasets Advanced Topics


    Anchor
    BestPractices
    BestPractices
    Best Practices and Troubleshooting

    Common Issues and Solutions

    Connection loss between project and database

    Database Timeout Configuration: The database may have a timeout setting that automatically disconnects idle connections after a certain period of time. It's recommended to check the database's timeout setting and adjust it, if necessary, to ensure that the connection remains active overnight.

    Power Settings: It's also suggested to check the computer's power settings to ensure that it doesn's not entering t enter sleep or hibernation mode during a certain idle momentmoments, which could cause a loss of connection to the database. Adjusting these settings to keep the computer active during these idle moments may resolve the issue.

    Database Connection Problem

    In the DB configuration, there is always a "Test" button to ensure that the connection is happening correctly. When there is a problem, the return of this button is an error message, usually returned by the database provider itself. The most common errors are: invalid user, invalid password, computer without access to the database, incorrect form of authentication.

    Issue: Error accessing the Database Table

    Once the connection is established, the Table configuration is specific to a table. In the "Table" combobox, the list of available tables automatically appears. It is possible, via script, to change which table will be accessed. However, care must be taken that the table exists and that the configuration is done using the correct name. The same care must be taken when Queries are used, as it is the user's responsibility to type the correct table name, as well as the syntax of the separators.

    Error in the Syntax of the Query

    It is the user's responsibility to type the correct SQLStatement of a query using the QueryBuilder. Table name, column, values, all can generate an error if used incorrectly. For example: comparing different types may not return the expected result, strings in general should be in single quotes. The separators and clauses available can vary between databases, for . For example:

    SQLServer

    Code Block
    languagesql
    titleQuery syntax
    SELECT TOP 10 * FROM table WHERE column = value

    SQLite

    Code Block
    languagesql
    titleQuery syntax
    SELECT * FROM table WHERE column = value LIMIT 10;

    Oracle

    Code Block
    languagesql
    titleQuery syntax
    SELECT * FROM table WHERE column = value AND ROWNUM <= 10;

    or new Oracle version

    Code Block
    languagesql
    titleQuery syntax
    SELECT * FROM table WHERE column = value FETCH FIRST 10 ROWS ONLY;

    IBM DB2

    Code Block
    languagesql
    titleQuery syntax
    SELECT * FROM table WHERE column = value FETCH FIRST 10 ROWS ONLY;


    ServerIP without TWebServer Running on the Remote Machine

    In some cases, the computer may not have access to the database. In this case, it is possible to create a gateway, routing the commands to be executed on the computer that has access to the database. The ServerIP field should be configured with the IP and port (<IP>:<port>), pointing to this computer that has access permission. This computer must have the software with the TWebServer running installed. It will automatically perform this gateway service and send the commands to the database.

    DataTable Returned NULL

    When a query is returned null, some error has occurred. Some common errors include: connection failure with the database, table not found, Dataset module is not running, incorrect query syntax. Check the return of the method using WithStatus when using a synchronous method or use the LastStatus and LastStatusMessage property when using asynchronous mode.

    DataTable Returned with 0 Rows

    When this happens, in general, there is a connection with the database and the table name is correct. In this case, the search condition is usually wrong, or the table is really empty. Check if the column names are correct and if the separators and clauses are valid.

    Dataset Module is Down

    Although the TServer is responsible for forwarding requests to the database, the management and communication with the TServer is done by the Dataset module, as well as the treatment of responses. Therefore, if you are having basic problems with access and execution of database access, the first thing to check is whether the module is set up to run and is actually running.

    Very High Response Time

    Sometimes, it may seem that access to the database is not being made, but what might actually be happening is that some accesses can return a very large amount of data, or the database may be overloaded, or with a bad configuration, causing it to have a low performance. Or even, the network itself can be overloaded and slow, and all these factors can impact the response time. In these cases, it is important to execute the Query directly in the database environment to be sure that the problem is not on the side of the database. Do this and check how long the database itself takes to execute the query. It is also worth checking the volume of data exchanged to have an idea of ??the related side effects.

    ** What are all these hashtags below for? **

    #Update

    the related side effects.

    Update of a table with the wrong schema (select before update)

    The Dataset module uses ADO technology, and many things are resolved at the level of this API. When we are going to perform an Update on a table, the schema of the table and controls in the .Net NET DataTable type are used. Therefore, if you are going to perform an update passing a Tag or .net NET DataTable object as a parameter, it is important that this object respects the schema of the destination Table in the database. Normally, a Select command must have been given at some point to obtain the correct schema used by the bank. After this, it is easy to add, remove, and modify values in this DataTable and update it back to the physical table in the database.

    #Where

    Where condition CaseSensitive

    Case sensitivity in a WHERE clause depends on the database and the configuration of the database you are using. For example, in MySQL, queries are case-insensitive by default, which means 'abc' and 'ABC' would be considered equal. However, this can be changed with specific database settings. In SQL Server, case sensitivity is also determined by the database configuration. In PostgreSQL, queries are case-sensitive by default, so 'abc' and 'ABC' would be considered different. Therefore, it really depends on the specific database and the settings of that database. If you need to ensure case-insensitivity in a query, you can use functions like UPPER() or LOWER() to convert all values to upper or lower case before comparison. For example:

    Code Block
    languagesql
    titleQuery syntax
    SELECT * FROM table WHERE LOWER(column) = LOWER(value);

    This query will return records where the column matches the value, regardless of capitalization.

    #Performance

    Performance

    The Dataset module's performance depends on many factors, including database performance, network latency, and the complexity of executing SQL queries. The platform will minimize overhead and execute queries as efficiently as possible. However, ultimately, the performance of the Dataset module is tied to these external factors. It's essential to design your database schema and queries with performance in mind and consider investing in high-quality hardware and network infrastructure to ensure optimal performance.

    Best Practices and Recommendations

    #Error

    Error Handling

    Error handling in the Dataset module is straightforward. Suppose an error occurs during the execution of a command. The error message will update the module's Error property (Last Status). You can monitor this property to handle errors in your application. Furthermore, suppose Error handling in the Dataset module is straightforward. If an error occurs during the execution of a synchronous method. In that case, the process will return an empty Data Table, and update the Error property. Alternatively, you can call methods like SelectCommandWithStatus, where the status will be an output parameter in the method.These are some of the key points you should keep in mind while using the Dataset module. It's a powerful tool that provides much flexibility. However, it also requires careful use and understanding of its features and limitations. Always keep best practices in mind when designing and implementing your database interactions. Feel free to seek expert advice if you need clarification on anythingof a command, the error message will update the module's Error property (Last Status). You can monitor this property to handle errors in your application. Furthermore, if an error occurs during the execution of a synchronous method, the process will return an empty DataTable and update the Error property. Alternatively, you can call methods like SelectCommandWithStatus, where the status will be an output parameter in the method.


    In this section:

    Page Tree
    root@self
    spacesV10

    ...