SQL  database can be used for managing data generated by the automation system. Generated data can be stored in a local database or in the cloud by using different methods. In our fictitious home automation system, we shall use the MS SQL server. We shall learn how to install the SQL server to the local machine or on any other devices such as PLC. There are two parts to this tutorial, installing the SQL server and using the SQL server for our home automation project, to understand we need to study a bit about modeling of data that means we need to go through some sample applications.

SQL Server Installation to PC and PLC

We need to install a database on our machine so that data generated by different sensors can be stored in the database. We need to install a database on our computer. Follow these simple steps to install it and learn how we can make a sample application that fits our automation project. Continue reading.

Display Data from SQL to HMI

Display Data to TwinCAT HMI from SQL Server

We need to model our system so that we can read and write data to the system or we can update the system based on the event. First, we need to find relations among different entities in the system. We shall use the fluent-NHibernate module. If we use this module then we don’t need to write all the SQL command by ourselves. We shall provide an example with full source code to understand how we display data from SQL server to TwinCAT HMI using JSON. Continue reading.

Windows Form SQL APP1

The best way to understand fluent NHibernate is to make a simple application by using C#  in windows platform.  I found a YouTube example  (https://www.youtube.com/watch?v=HQcnLP0iYQo&t=8s) video, I watched and wrote the code myself code as shown in the video.  We shall explain step by step. Actually this code should  be understood before doing the TwinCAT example. Explore  and continue reading.

Windows Form SQL APP2

We need to model our system so that we can read and write data to the system or we can update the system based on the event. First, we need to find relations among different entities in the system. We shall use the fluent-NHibernate module. If we use this module then we don’t need to write all the SQL command by ourselves. We shall provide 3 examples that will help us to understand the data modeling. Continue reading.

Direct SQL Connection

This section describes how to use connections directly for different purposes. We shall show how to delete a row, table, etc. This can be used in conjunction with the fluent NHibernate if we can’t do something by NHibernate.  Continue reading.

Generating report from SQL

Generate a report from SQL database coming by using C# and SQL Server Management Studio  Continue reading.